2013-10-23 28 views
0

我有以下简单的HTML。它在使用ExtJS 4时工作,但在使用ExtJS 4.2时不起作用。从webserivce Json商店在ExtJS 4.0但不是4.2

在这两种情况下,Web服务都被调用,但是当使用ExtJS 4.2时,store.data为空。

我猜这是问题(这里的东西是不是在ExtJS的4.2支持,但我不知道是什么):

Ext.define('Ext.AspWebAjaxProxy', { 
     extend: 'Ext.data.proxy.Ajax', 
     require: 'Ext.data', 

     buildRequest: function (operation) { 
      var params = Ext.applyIf(operation.params || {}, this.extraParams || {}), 
           request; 
      params = Ext.applyIf(params, this.getParams(params, operation)); 
      if (operation.id && !params.id) { 
       params.id = operation.id; 
      } 

      params = Ext.JSON.encode(params); 

      request = Ext.create('Ext.data.Request', { 
       params: params, 
       action: operation.action, 
       records: operation.records, 
       operation: operation, 
       url: operation.url 
      }); 
      request.url = this.buildUrl(request); 
      operation.request = request; 
      return request; 
     } 
    }); 

这是完整的代码:

<body> 
<div id="ext-grid"> 
</div> 
<script type="text/javascript"> 
    Ext.require([ 
      'Ext.grid.*', 
      'Ext.data.*', 
      'Ext.panel.*', 
      'Ext.layout.container.Border' 
     ]); 

    Ext.define('Ext.AspWebAjaxProxy', { 
     extend: 'Ext.data.proxy.Ajax', 
     require: 'Ext.data', 

     buildRequest: function (operation) { 
      var params = Ext.applyIf(operation.params || {}, this.extraParams || {}), 
           request; 
      params = Ext.applyIf(params, this.getParams(params, operation)); 
      if (operation.id && !params.id) { 
       params.id = operation.id; 
      } 

      params = Ext.JSON.encode(params); 

      request = Ext.create('Ext.data.Request', { 
       params: params, 
       action: operation.action, 
       records: operation.records, 
       operation: operation, 
       url: operation.url 
      }); 
      request.url = this.buildUrl(request); 
      operation.request = request; 
      return request; 
     } 
    }); 

    Ext.onReady(function() { 
     Ext.define('Actors', { 
      extend: 'Ext.data.Model', 
      fields: ['FirstName', 'LastName', 'EmailAddress', 'Salary'] 
     }); 


     store = new Ext.data.Store(
      { 
       proxy: new Ext.AspWebAjaxProxy({ 
        url: 'service.asmx/LoadRecords', 
        actionMethods: { 
         read: 'POST' 
        }, 
        reader: { 
         type: 'json', 
         model: 'Actors', 
         root: 'd' 
        }, 
        headers: { 
         'Content-Type': 'application/json; charset=utf-8' 
        } 
       }) 
      }); 


     var grid = Ext.create('Ext.grid.Panel', { 
      store: store, 
      columns: [ 
         { text: 'FirstName', dataIndex: 'FirstName', width: 280, sortable: true }, 
         { text: 'LastName', dataIndex: 'LastName', sortable: true }, 
         { text: 'EmailAddress', dataIndex: 'EmailAddress', width: 150, sortable: true }, 
         { text: 'Salary', dataIndex: 'Salary', sortable: true } 
         ], 
      renderTo: 'ext-grid' 
     }); 

     store.load(); 
    }); 
</script> 
</body> 

这是JSON:

{ 
    "d": [ 
     { 
      "__type": "CrystalBall.service+Record", 
      "FirstName": "Palash", 
      "LastName": "Debnath", 
      "EmailAddress": "[email protected]", 
      "Salary": 100 
     }, 
     { 
      "__type": "CrystalBall.service+Record", 
      "FirstName": "Pritam", 
      "LastName": "Debnath", 
      "EmailAddress": "[email protected]", 
      "Salary": 200 
     } 
    ] 
} 
+0

你回来的JSON非常标准,它工作。请求的样子应该如何?如果你能详细说明这一点,我可以帮助你更好。 –

+0

我解决了这个问题,我删除了ActionMethod并将GET服务调用为web服务。 – Alophind

回答

0

我认为问题是,你重新定义方法buildRequest。这个函数的内部可能在版本4.0和4.2之间发生了变化。

ExtJs 4.2提供了非常广泛的可能性来配置发送请求的方式,因此不需要重新定义该功能。

+0

你是对的,我使用了常规的Ext.Data.HttpProxy,它现在可以工作。 – Alophind