KendoUI:用于多个网格的多级JSON数据源
KendoUI: one multi-level JSON dataSource for multiple grids
我有一个JSON数据源,看起来像这样:
var productDataSource = new kendo.data.DataSource({
transport: {
read: {
url: 'http://...',
dataType: "json"
}
},
pageSize: 10
});
并返回如下内容:
{
"ProdSet1":[
{
"Name": "Product 1-1",
"Price": 20,
"Quantity": 50,
"Change": 4
},
{
"Name": "Product 1-2",
"Price": 14,
"Quantity": 74,
"Change": 5
}
],
"ProdSet2":[
{
"Name": "Product 2-1",
"Price": 15,
"Quantity": 12,
"Change": 2
}
]
}
然后我有多个网格使用这个数据源:
$("#prodSet1").kendoGrid({
dataSource: productDataSource,
columns: [
{ field: "ProdSet1[0].Name", title: "Name" },
{ field: "ProdSet1[0].Price", title: "Price" },
{ field: "ProdSet1[0].Quantity", title: "Quantity" },
{ field: "ProdSet1[0].Change", title: "Change" }
]
});
$("#prodSet2").kendoGrid({
dataSource: productDataSource,
columns: [
{ field: "ProdSet2[0].Name", title: "Name" },
{ field: "ProdSet2[0].Price", title: "Price" },
{ field: "ProdSet2[0].Quantity", title: "Quantity" },
{ field: "ProdSet2[0].Change", title: "Change" }
]
});
但是做{ field: "ProdSet1[0].Name" ...}
不起作用。
如何引用正确的产品数据?
因为集合是在返回对象中命名的,所以可以设置模式。data属性到每个ProdSet,并绑定一个网格。
我将手动从数据源获取数据,使用datasource.read()
var datafromService = productDataSource.read();
文档…http://docs.telerik.com/kendo-ui/documentation/api/framework/datasource methods-read
然后将每个网格绑定到该datafromService,每个网格指定要绑定到的JSON对象中的集合。
$("#prodSet1").kendoGrid({
dataSource: {
data: datafromService,
schema: {
data: 'ProdSet1'
}
},
columns: [
{ field: "Name", title: "Name" },
{ field: "Price", title: "Price" },
{ field: "Quantity", title: "Quantity" },
{ field: "Change", title: "Change" }
]
});
和
$("#prodSet2").kendoGrid({
dataSource: {
data: datafromService,
schema: {
data: 'ProdSet2'
}
},
columns: [
{ field: "Name", title: "Name" },
{ field: "Price", title: "Price" },
{ field: "Quantity", title: "Quantity" },
{ field: "Change", title: "Change" }
]
});
现在它们将被绑定到同一组数据,只是显示来自JSON数据的不同集合。
看到样本…http://jsbin.com/dokub/1/edit
如果您需要完整的CRUD操作,那就放到另一个袋子里。
相关文章:
- 使用PHP,我如何将JSON blob附加到现有的多级JSON对象
- jqgrid发布多级json
- angular js多个复选框过滤多级JSON
- Javascript JSON 解析和字符串化用于多级
- JSON多级对象
- 在多级json对象中使用变量作为键
- JavaScript JSON 多级迭代解析
- 生成多级 JSON
- 使用来自 JSON 对象的数组表示法进行多级属性检索
- 如何读取多级 json
- 在javascript中编辑多级json,类似Ruby的翻译可以读取它们(从array/string)
- 从平面json生成(多级)flare.json数据格式
- 处理多级json
- AngularJS:使用多级 JSON 进行过滤和唯一
- 为多级JSON创建一个简单的元数据
- 使用jQuery的多级JSON
- 使用getJSON从多级JSON读取到Google Chart
- javascript:解析多级json数组
- 从多级JSON对象中选择性地提取数据
- KendoUI:用于多个网格的多级JSON数据源