1
我有数据的样本JSON对象中找到一个值:填充与JSON一个DataTable,需要渲染的超链接在一列中,在不同的JSON字段
[
{
"id": 1,
"title": "Fred",
"author": "Flintstone"
}, {
"id": 2,
"title": "Fred",
"author": "Flintstone"
}, {
"id": 3,
"title": "Fred",
"author": "Flintstone"
}.....
HTML
<table class="table" id="tblRunbook">
<thead>
<tr>
<th width="60px">ID</th>
<th width="300px">Title</th>
<th width="200px">Author</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
JavaScript的:
$(document).ready(function() {
$('#tblRunbook').dataTable({
<!-- Retrieve a static json file, you could also have a URL to a controller method. -->
"sAjaxSource" : "/getRunbooks",
"sAjaxDataProp": "",
<!-- Indicate to dataTable what the field names are we want, in the order we want them in the table. -->
"aoColumns": [
{"data": "id"},
{"data": "title",
"render": function (data, type, row, meta) {
return '<a href="runbook?rbID=" + data.id + '>' + data + '</a>';}
},
{"data": "author"}
]
});
});
与ID
列将被隐藏,但我想使链接runbook?rbID = ID
。我想访问JSON对象中的前一个字段,在此例中为"data" : "id"
,并将其设置在函数返回'<a href="runbook?rbID=" + data.id + '>'
的第二个字段中,其中data.id
是ID
。
您可以使用jQuery地图来创建新的数据源,从其他数据源无限制,并使用新的模型的数据表。 Datatables只能使用一个源。但是如果它分配的数据可能很慢,那么在服务器上重建模型可能是一个更好的主意。 – ppumkin
我认为这个http://www.datatables.net/forums/discussion/200/getting-values-from-hidden-column-rows将有助于解决。 –