[英]Datatables createdRow function not setting id to row element
"createdRow": function (row, data, dataIndex) {
var a = dataIndex;
alert(a);
var i = policyInfoArray[dataIndex].id;
alert(i);
$('td', row).eq(0).attr('id', i);
}
When I run this code, alert(a) pops up correctly and alert(i) gives me the correct result as well. 当我运行此代码时,alert(a)会正确弹出,而alert(i)也能给我正确的结果。 but for some reason
但由于某种原因
$('td', row).eq(0).attr('id', i);
gives me an error when I put i in there. 当我把我放在那里时,给我一个错误。 However this:
但是,这:
$('td', row).eq(0).attr('id', 5);
works fine. 工作正常。 Can someone please direct me ask to what I am doing wrong?
有人可以指示我问我在做什么错吗?
It looks like your code is setting the id to the first td
element of the table row. 看起来您的代码正在将ID设置为表格行的第一个
td
元素。 If you change the last line of your function to this, it will add the id to the row element itself: 如果将函数的最后一行更改为此,它将id添加到row元素本身:
$(row).eq(0).attr('id', i);
It is likely that the problem you see is to do with the data in your policyInfoArray array. 您看到的问题很可能与policyInfoArray数组中的数据有关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.