我的fuelux数据网格在主干渲染功能中看起来像这样
var dataSource = new StaticDataSource({
columns: [
{
property: 'id',
label: 'id',
sortable: true
},
{
property: 'name',
label: 'groups',
sortable: true
},
{
property: 'name',
label: 'Roles',
sortable: true
}
],
data: this.collection,
delay: 250
});
$('#sectionName').html('Groups');
$('#MyGrid').datagrid({
dataSource: dataSource,
stretchHeight: true
});
this.collection 返回 json 如下
[
{
"id":1,
"roles":[
{"id":1,"authority":"ROLE1"},
{"id":2,"authority":"ROLE2"},
{"id":3,"authority":"ROLE3"}
],
"groups":[
{"id":1,"name":"A"},
{"id":2,"name":"B"},
{"id":3,"name":"C"}
]
},
{
"id":2,
"roles":[
{"id":5,"authority":"ROLE4"},
{"id":5,"authority":"ROLE5"},
{"id":6,"authority":"ROLE6"}
],
"groups":[
{"id":4,"name":"D"},
{"id":5,"name":"E"},
{"id":6,"name":"F"}
]
}
]
我希望fuelux datagrid 具有列ID、角色和组。它应该如下所示:
id roles groups
1 role1, role2 , role3 A, B, C
12 role3, role4 , role5 D, E, F
我试图编写类似这样的格式化程序函数,但它不起作用
var dataSource = new StaticDataSource({
columns: [
{
property: 'id',
label: 'id',
sortable: true
},
{
property: 'name',
label: 'groups',
sortable: true
},
{
property: 'name',
label: 'Roles',
sortable: true
}
],
formatter: function (items) {
$.each(items, function (index, item) {
item.roles= //string made from groups with comma
item.groups= //string made from roles with comma
},
data: this.collection,
delay: 250
});
$('#MyGrid').datagrid({
//as above
});
formatter: function (items) {
$.each(items, function (index, item) {
item.roles= //string of roles made from roles with comma
item.groups= /string of groups made from groups with comma
});
},
如果这里有人可以帮助我,那将是很大的帮助。