我如何使用嵌套Json填充剑道UI网格
How can I use nested Json to populate Kendo UI grid?
如何使用嵌套JSON填充剑道UI网格
JSON就像
var myJson:
[{"oneType":[
{"id":1,"name":"John Doe"},
{"id":2,"name":"Don Joeh"}
]},
{"othertype":"working"},
{"otherstuff":"xyz"}]
}];
和我想要剑道UI网格列作为Id,名称,OtherType和OtherStuff。
提前感谢!
对于复杂的JSON结构,您可以使用schema.parse
var grid = $("#grid").kendoGrid({
dataSource : {
data : [
{
"oneType": [
{"id": 1, "name": "John Doe"},
{"id": 2, "name": "Don Joeh"}
]
},
{"othertype": "working"},
{"otherstuff": "xyz"}
],
pageSize: 10,
schema : {
parse : function(d) {
for (var i = 0; i < d.length; i++) {
if (d[i].oneType) {
return d[i].oneType;
}
}
return [];
}
}
}
}).data("kendoGrid");
如果您将JSON稍微更改为:
{
"oneType" : [
{"id": 1, "name": "John Doe"},
{"id": 2, "name": "Don Joeh"}
],
"othertype" : "working",
"otherstuff": "xyz"
}
则可以使用:
var grid = $("#grid").kendoGrid({
dataSource: {
data : {
"oneType" : [
{"id": 1, "name": "John Doe"},
{"id": 2, "name": "Don Joeh"}
],
"othertype" : "working",
"otherstuff": "xyz"
},
pageSize: 10,
schema : {
data: "oneType"
}
}
}).data("kendoGrid");
我只是想提交另一个基于OnaBai的答案。
http://jsfiddle.net/L6LwW/17/HTML:<script id="message-template" type="text/x-kendo-template">
#for (var i = 0; i
< ddl.length; i++) {# <li><span>#=ddl[i].value#</li>
#}#
</script>
<div id="grid"></div>
JS:
var grid = $("#grid").kendoGrid({
dataSource: {
data: [
[{
"id": 1,
"name": "John Doe",
"ddl": [{
"key": 1,
"value": "hello"
}, {
"key": 1,
"value": "hello"
}]
}, {
"id": 2,
"name": "Don Joeh",
"ddl": [{
"key": 1,
"value": "hello"
}, {
"key": 1,
"value": "hello"
}]
}]
],
pageSize: 10,
schema: {
parse: function(d) {
for (var i = 0; i < d.length; i++) {
if (d[i]) {
return d[i];
}
}
return [];
}
}
},
columns: [{
field: "id",
title: "ID"
}, {
field: "name",
title: "Name"
}, {
field: "ddl",
title: "DDL",
width: "180px",
template: kendo.template($("#message-template").html())
} //template: "#=ddl.value#" }
]
}).data("kendoGrid");
相关文章:
- 我可以更改剑道UI网格吗's的外键值
- 如何在Angular UI网格中选择下一行
- 使用导航属性创建Kendo UI网格模型的问题
- ui网格将单元格显示为选择标记
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- 使用按钮的Angular UI网格过滤器
- ui网格:在自定义表头模板中触发排序
- 在有角度的ui网格中设置动态列的问题
- angularjs中的ng网格和ui网格有什么区别
- 在编辑内联模式下禁用Kendo Ui网格按钮
- 在angularjs UI网格列中选择下拉菜单不适用于外部editcellTemplate
- 将模型从Kendo Mvc UI网格传递到javascript函数
- 如何在可扩展ui网格中绑定子网格事件
- Typescript Kendo UI网格列类型错误
- ui网格如何在单击行时选中复选框
- Kendo UI网格:数据源刷新后,我丢失了分页
- Kendo UI网格复选框列字段未定义
- 无法将行保存在Angular UI网格中的可展开行中
- Angular UI网格:如何通过第一个UI网格中的按钮使第二个UI网格可见
- Kendo UI网格自定义编辑按钮