我的服务器端数据如下 jQuery datatable .
"data": [
{
"id": 1,
"title": 'Hello World"
"category": [
{
"id": 1,
"title": "Hello World"
},
{
"id": 1,
"title": "Foo Bar"
},
]
}
]
现在我需要在数据表的类别列单元格中将这些“类别”显示为超链接,并且应该以逗号分隔,如下所示
来源:<a href="ID">Hello World</a>, <a href="ID">Foo Bar</a>
示例:Hello World , Foo Bar等等...
我已经可以使用 "render": "[, ].title"
将其呈现为逗号分隔但不是这个级别作为超链接。谁能帮我吗?
编辑
{ data: 'category',
render: function ( data, type, full, meta ) {
$.each(data.category, function( index, value ) {
return value.title;
});
}
},
这就是我到目前为止所做的。但仍然不起作用。我需要将 title 和 id 传递到这个循环中。所以我可以用它来构建超链接。
最佳答案
在没有更多背景的情况下,我在这里非常盲目,但是......
{ data: 'category',
render: function ( data, type, full, meta ) {
var result = '';
$.each(full.category, function( index, value ) {
result = result + '<a href="' + value.id + '">' + value.title + '</a>';
if (index < full.category.length)
result = result + ', ';
});
return result;
}
},
关于javascript - jQuery 数据表对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38595879/