添加模板时更改 json 属性 上的图像
Change image on json property when appending template
一张图像可以有 [1,2,3,4] 个状态(占位符、处理中、接受、拒绝),格式为 JSON。我正在想出一个函数来检查 属性 和 select 放置在小胡子 HTML.
中的正确图像
我尝试了以下方法:
for (let i=0;i<101;i++) {
var output = Mustache.render(template, view[i]);
$('#entryTable tbody').append(output);
if (view[i].status == 2) {
this.getElementById('picture1').src= 'img/analyzing.png';
} else if (view[i].status == 3) {
this.getElementById('picture1').src= 'img/irrelevant.png';
console.log(this)
} else if (view [i].status == 4) {
this.getElementById('picture1').src= 'img/relevant.png';
}
但是 'this' 指的是文档而不是图像 -> 它只更改出现的第一张图像(对于所有条目,重复)。
接下来,我尝试了:
for (let i=0;i<101;i++) {
var output = Mustache.render(template, view[i]);
$('#entryTable tbody').append(function() {
//the default image in the template is state 1, hence it checks for state 2 and above
if (view[i].state == 2) {
this.getElementById('picture1').src= 'img/analyzing.png';
} else if (view[i].state == 3) {
this.getElementById('picture1').src= 'img/irrelevant.png';
console.log(this)
} else if (view [i].state == 4) {
this.getElementById('picture1').src= 'img/relevant.png';
}
return output;
});
这似乎(?)有效但只附加了一个条目。
我没有使用 'this' 的经验,我如何才能正确 context/scope 更改条目特定图像?
已解决
if (view[i].state === 1) {
$("#entryTable tbody tr .status1").eq(i).attr("src", "img/analyzing.png");
} else if (view[i].state === 3) {
$("#entryTable tbody tr .status1").eq(i).attr("src", "img/irrelevant.png");
} else if (view[i].state === 4) {
$("#entryTable tbody tr .status1").eq(i).attr("src", "img/relevant.png");
}
}
一张图像可以有 [1,2,3,4] 个状态(占位符、处理中、接受、拒绝),格式为 JSON。我正在想出一个函数来检查 属性 和 select 放置在小胡子 HTML.
中的正确图像我尝试了以下方法:
for (let i=0;i<101;i++) {
var output = Mustache.render(template, view[i]);
$('#entryTable tbody').append(output);
if (view[i].status == 2) {
this.getElementById('picture1').src= 'img/analyzing.png';
} else if (view[i].status == 3) {
this.getElementById('picture1').src= 'img/irrelevant.png';
console.log(this)
} else if (view [i].status == 4) {
this.getElementById('picture1').src= 'img/relevant.png';
}
但是 'this' 指的是文档而不是图像 -> 它只更改出现的第一张图像(对于所有条目,重复)。
接下来,我尝试了:
for (let i=0;i<101;i++) {
var output = Mustache.render(template, view[i]);
$('#entryTable tbody').append(function() {
//the default image in the template is state 1, hence it checks for state 2 and above
if (view[i].state == 2) {
this.getElementById('picture1').src= 'img/analyzing.png';
} else if (view[i].state == 3) {
this.getElementById('picture1').src= 'img/irrelevant.png';
console.log(this)
} else if (view [i].state == 4) {
this.getElementById('picture1').src= 'img/relevant.png';
}
return output;
});
这似乎(?)有效但只附加了一个条目。
我没有使用 'this' 的经验,我如何才能正确 context/scope 更改条目特定图像?
已解决
if (view[i].state === 1) {
$("#entryTable tbody tr .status1").eq(i).attr("src", "img/analyzing.png");
} else if (view[i].state === 3) {
$("#entryTable tbody tr .status1").eq(i).attr("src", "img/irrelevant.png");
} else if (view[i].state === 4) {
$("#entryTable tbody tr .status1").eq(i).attr("src", "img/relevant.png");
}
}