1

我的 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 返回的值显示在数据网格中。我不断收到“抱歉发生错误!” 而不是数据网格渲染。我换了

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"}];

并且数据网格可以正常工作!任何帮助将不胜感激

4

1 回答 1

0

Issue Resolved. Revised Code

enter code hereif (data.Success) {
var store = new dojo.data.ItemFileReadStore({ data: { items: data.ActivityTypes} }); var layout = [[ { 'name': 'ID', 'field': 'id', 'width': '20%' }, { 'name': 'Activity Type', 'field': 'label', 'width': '80%' }

]];

Key was to pass data in ActivityTypes directly to the store.

于 2012-10-25T05:08:26.620 回答