2012-03-20 63 views
0

ASP.NET的安全功能之一在这里被证明是一座山 - 在返回JSON响应时,“d”属性添加看起来令人困惑ExtJS when我试图动态地重新配置一个网格面板,导致它在尝试生成新的列结构时失败。ExtJS4 - 在ASP.NET中重新配置网格 - JSON结构问题

I,接着nicholasnet此解决方案: http://www.sencha.com/forum/showthread.php?179861-Dynamic-grid-columns-store-fields

,它工作精美,直到JSON有效载荷被围绕“d”属性,例如包裹

{"d":{ 
    "metaData": { 
     "root": "data", 
     "fields": [{ 
      "type": "int", 
      "name": "id", 
      "hidden": true, 
      "header": "id", 
      "groupable": false, 
      "dataIndex": "id" 
     }, ...omitted for brevity...] 
    }, 
    "success": true, 
    "data": [{ 
     "id": "1", 
     "controller": "Permissions", 
     "description": "Allow to see permission by roles", 
     "administrator": true, 
     "marketing": false 
    }] 
    } 
} 

我无法弄清楚如何告诉ExtJS绕过这个问题。 我试过将AJAX阅读器的“root”属性设置为"d.data",但这会导致网格显示正确的行数但根本没有数据。

我已经拥有JSON中列元数据("name", "header", "dataIndex")所需的所有属性描述符,所以我不相信JSON结构是原因。我当时的主要领导是在事件处理程序:

store.on 
({ 
    'load' : 
    { 
     fn: function(store, records, success, operation, eOpts) 
     { 
      grid.reconfigure(store,store.proxy.reader.fields); 
     }, 
     scope: this 
    } 
}, this); 

fieldshistoryStore.proxy.reader.fields部分是不确定的,当我通过“d” -wrapped JSON。任何人有任何想法,为什么这是或如何解决这个问题?

编辑:我店/代理

Ext.define('pr.store.Store-History', { 
    extend: 'Ext.data.Store', 
    model: 'pr.model.Model-History', 
    proxy: { 

     type: 'ajax', 
     url: '/data/history.json', 
     reader: { 
      type: 'json', 
      root: 'd' 
     } 
} 
}); 
+0

您对阅读器对象的配置是什么? – sha 2012-03-20 15:00:48

+0

我已将我的商店类添加到OP。 – MHTri 2012-03-20 15:21:27

+0

你可以尝试阅读器作为'读者:{ 类型:'json', root:'d.data',successProperty:'d.success' }' – 2012-03-20 15:29:31

回答

1
Ext.define('pr.store.Store-History', { 
    extend: 'Ext.data.Store', 
    model: 'pr.model.Model-History', 
    proxy: { 

     type: 'ajax', 
     url: '/data/history.json', 
     reader: { 
      type: 'json', 
      root: 'data', 
      readRecords: function(data) { 
       //this has to be before the call to super because we use the meta data in the superclass readRecords 
       var rootNode = this.getRoot(data); 
       if (rootNode.metaData) { 
        this.onMetaChange(rootNode.metaData); // data used to update fields 
       } 

       /** 
       * @deprecated will be removed in Ext JS 5.0. This is just a copy of this.rawData - use that instead 
       * @property {Object} jsonData 
       */ 
       this.jsonData = rootNode; 
       return this.callParent([rootNode]); // data used to get root element and then get data from it 
      }, 
     } 
    } 
}); 

更新: 你是不是在读者越来越领域,因为从获得的数据不处理您的包裹数据字段的默认代码,所以您需要更改'readRecords'功能来处理您的自定义数据

+0

我以前试过这个。请再次阅读OP。它产生的所有行数都是正确的,但没有显示数据。 – MHTri 2012-03-20 17:16:09

+0

检查更新的答案:) – 2012-03-20 17:47:24

+0

谢谢,这是我的同事在调试会议后得出的结论。而不是data.d.data,虽然我使用this.getRoot(data).metaData,以便我可以指定什么数据的根可以使其他框架决定与ASP.NET一样安全;) – MHTri 2012-03-21 09:45:18