0

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

WCF 接口设置为 WebMessageFormat.JSON:

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

在网络配置中,我已将端点行为设置为使用“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 和响应标头: Content-Length: 2790 Content-Type: text/html

任何帮助将不胜感激!

4

2 回答 2

1

要使 gridx 控件与 JSONRest 一起使用,您需要在响应中返回一个内容范围,例如 Content-Range: items 0-24/66。

有关详细信息,请参阅此页面 http://dojotoolkit.org/reference-guide/1.9/dojo/store/JsonRest.html

于 2013-11-29T18:04:55.923 回答
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();
于 2013-11-27T21:01:23.400 回答