我是第一次使用JSON ……
并希望用我的JSON数据填充我的数据网格,
这是我的JSON数据:
并希望用我的JSON数据填充我的数据网格,
这是我的JSON数据:
{ "head": { "vars": [ "s","fname","lname" ] },"results": { "bindings": [ { "s": { "type": "uri","value": "http://tn.gov.in/Person/41" },"fname": { "type": "literal","value": " },"lname": { "type": "literal",n" } },{ "s": { "type": "uri","value": "http://tn.gov.in/Person/37" },"value": "sh" },"value": "Vvan" } },"value": "http://tn.gov.in/Person/39" },"value": "Vavan " },"value": "Sran" } } ] } }
我想在数据网格中显示fname和lname我应该怎么做呢?
任何人都可以提供适用于上述JSON的示例代码吗?我尝试了很多例子,我得到一个空格
这里的关键点是,在dojo网格中使用之前,您需要先转换数据.
原文链接:https://www.f2er.com/dojo/290894.html现场演示可在here找到.
dojo.require("dojox.grid.DataGrid"); dojo.require("dojo.data.ItemFileReadStore"); dojo.addOnLoad(function() { var data = { "head": { "vars": [ "s","lname" ] },"results": { "bindings": [ { "s": { "type": "uri","value": "Gayathri" },"value": "Vasudevan" } },{ "s": { "type": "uri","value": "Magesh" },"value": "Vasudevan " },"value": "Srinivasan" } } ] } }; var items = dojo.map(data.results.bindings,function(binding) { return {fname : binding.fname.value,lname : binding.lname.value}; }); var store = new dojo.data.ItemFileReadStore({ data : { items : items } }); _createGrid(store); function _createGrid(store) { var layout = _getGridLayout(),node = dojo.create("div",{},dojo.byId("grid"),"only"); var grid = new dojox.grid.DataGrid({ store : store,structure : layout,rowsPerPage: 10 },node); grid.update(); grid.startup(); return grid; } function _getGridLayout() { return [[ { field : "fname",name : "First Name",width : "50%"},{ field : "lname",name : "Last Name",width : "50%" } ]]; } });