【发布时间】:2019-11-04 11:03:46
【问题描述】:
我的表格行看起来像这样
{% for item in items %}
<tr id="labels" data-index="{{ forloop.counter }}"> </tr>
{% endfor %}
我有这个 json 数据:
"labels": [
"A",
"B",
"C ",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"
],
我正在尝试同时迭代表行和 json 数据,以便我可以为每个表行分配其标签。
jQuery.each(labels, function() {
newlabel = this;
document.querySelectorAll('#labels').forEach(function (element, index) {
element.innerHTML = newlabel;
});
})},
但是这样一来,所有行都填充了字母 Z,而不是按字母顺序排列的 A-Z。
感谢您的帮助
【问题讨论】: