Dojo gridx 1.9和JsonRest和WCF REST服务

时间:2013-11-27 18:51:09

标签: dojo.gridx

我正在尝试使用WCF REST服务学习Dojo的GridX。我收到“没有要显示的项目

WCF接口设置为WebMessageFormat.JSON:

[OperationContract]
[WebGet (ResponseFormat=WebMessageFormat.Json)]
List<Account> GetAccountList();

在Web配置中,我已将端点行为设置为使用“webHttpBinding”

这是脚本:

require([
              'dojo/store/JsonRest',
              'gridx/Grid',
              'gridx/core/model/cache/Async', 
              'dojo/domReady!'
        ], function (Store, Grid, Cache) {


            var jsonStore = new Store({
                target: "http://server/web/Service1.svc/GetAccount"  
            });

         //test - this is working, I am seeing the data
         //jsonStore.query({}, { start: 0 }).then(function (items) {
         //    alert(items[0].AccountName);
         //});


            var columns = [
               { field: 'AccountId', name: 'AccountId' },
               { field: 'AccountName', name: 'AccountName' },
               { field: 'AccountNumber', name: 'AccountNumber' }
            ];


             var grid = new Grid({
             store: jsonStore,
             cacheClass: Cache,
             autoHeight: true,           
             structure: columns             
          });

          grid.placeAt("gridNode");

          grid.startup();

     });

我检查了Fiddler和响应标题: 内容长度:2790 内容类型:text / html

Anyhelp将不胜感激!

2 个答案:

答案 0 :(得分:1)

要使gridx控件与JSONRest一起使用,您需要在响应中返回内容范围,例如内容范围:项目0-24 / 66.

请参阅此页面了解详情 http://dojotoolkit.org/reference-guide/1.9/dojo/store/JsonRest.html

答案 1 :(得分:0)

将这些添加到需要部分:

'dojo/store/Cache',
'gridx/core/model/cache/Async',
'dojo/store/Observable',
'dojo/store/JsonRest',
'dojo/data/ObjectStore',
'dojo/store/Memory',

使用以下内容添加/编辑网格功能:

        var requestString = "http://server/web/Service1.svc/GetAccount";        
        var store = new Cache(new JsonRest({target:requestString, idProperty: "id"}), Memory());
        var objectStore = ObjectStore({objectStore: store}); 

        window.grid = new Grid({
            store: objectStore,
            cacheClass: Async,
            autoHeight: true,
            structure: layout,
            modules: [SingleSort]
        });

调用下面的网格:

        grid.placeAt('gridContainer');
        grid.startup();