【发布时间】:2017-10-16 10:22:40
【问题描述】:
我想将两个不同列的值呈现到我的 jquery 数据表中
https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js
https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css
$(document).ready(function(){
var table = $('#table').DataTable({
"ajax": {
"url": "data.json",
"dataSrc": "",
},
"columnDefs": [
{
"render": function (data, type, row) {
var result = 'The id is ' + data[0] + ' and the name is ' + data[1];
return result;
},
"targets": 0,
},
],
"columns": [
{
"data": "id"
},
{
"data": "name"
}
]
});
});
data.json:
[{
"id": "12",
"name": "Laura"
}]
但我的结果是:
The id is 12 and the name is undefined
【问题讨论】:
-
应该是
row[0]而不是data[0]。 -
@markpsmith 但是我的结果是:id 未定义,名称未定义
-
应该是
var result = 'The id is ' + row["id"] + ' and the name is ' + row["name"];
标签: javascript jquery ajax datatables