我正在尝试读取jQuery数据表的内容。我能够遍历所有行,但是我不知道如何获取内容。
这是我到目前为止所做的:
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var d = this.data();
var item = {
id: // Get first column content
description: //Get second column content
}
});
答案 0 :(得分:2)
有两种使用方式:
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var nodes = this.nodes().to$();
var item = {
id: nodes.find('td:eq(0)').text(), // Get first column content
description: nodes.find('td:eq(1)').text() // Get second column content
};
});
OR
table.rows().every(function (rowIdx, tableLoop, rowLoop) {
var item = {
id: this.cell(rowIdx,0).data(), // Get first column content
description: this.cell(rowIdx,1).data() // Get second column content
};
});
您可以找到更多详细信息here。
答案 1 :(得分:1)
我在某处使用了以下代码。也许这可以为您工作。
table.rows().iterator('row', function(context, rowIdx){
var item = {
id: $(this.row(rowIdx).node());
description: $(this.row(rowIdx).node());
}
});