我的WCF服务返回
{"Success":true,"Errors":null,"ActivityTypes":[{"id":1,"label":"Input"},{"id":2,"label":"Processing"},{"id":3,"label":"Exception Handling"},{"id":4,"label":"Quality Control"},{"id":5,"label":"Output"}]}
以下是我用于将其转换为Datagrid的代码
dojo.require("dojox.grid.DataGrid");
dojo.require("dojo.data.ItemFileReadStore");
var xhrArgs = {
url: xhreturn,
handleAs: "json",
preventCache: true
}
var deferred = dojo.xhrGet(xhrArgs);
deferred.then(
function (data) {
if (data.Success) {
rawdata = [data.GetActivityTypeList];
var store = new dojo.data.ItemFileReadStore({
data: { identifier: 'id', items: rawdata }
});
var layout = [[
{ 'name': 'Activity Type', 'field': 'label', 'width': '20%' }
]];
var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '5px'
},document.createElement('div'));
dojo.byId("gridDiv").appendChild(grid.domNode);
grid.startup();
standby.hide();
}
我试图获取ActivityTypes中返回的值以显示在datagrid中。我一直得到“抱歉错误!”而不是数据网格渲染。我换了
rawdata = [data.GetActivityTypeList];
用这个
rawdata = [{ "id": 1, "label": "Input" }, { "id": 2, "label": "Processing" }, { "id": 3, "label": "Exception Handling" }, { "id": 4, "label": "Quality Control" }, { "id": 5, "label": "Output"}];
并且datagrid没有任何问题!任何帮助将不胜感激
答案 0 :(得分:0)
enter code here
if(data.Success){
var store = new dojo.data.ItemFileReadStore({
data:{items:data.ActivityTypes}
});
var layout = [[
{'name':'ID','field':'id','width':'20%'},
{'name':'活动类型','字段':'标签','宽度':'80%'}
Key是将ActivityTypes中的数据直接传递给商店。