1

我正在尝试加载由 AJAX 请求回复到网格的 JSON 数据。我的店铺定义:

Ext.define('Report.store.CustomerDataStore', {
    extend: 'Ext.data.Store',
    requires: [
        'Report.model.Customer'
    ],

    constructor: function(cfg) {
        var me = this;
        cfg = cfg || {};
        me.callParent([Ext.apply({
            autoLoad: false,
            storeId: 'CustomerDataStore',
            model: 'Report.model.Customer',
            proxy: {
                type: 'ajax',
                url: '',
                reader: {
                    type: 'json',
                    root: 'data',
                    record: 'fields'
                }
            }
        }, cfg)]);
    }
});

我的应用程序中有一个按钮,定义如下:

xtype: 'button',
handler: function(button, event) {
    var queryform = this.up('form').getForm();
    var me = this;
    if(queryform.isValid())
    {
        Ext.Ajax.request({
            url: 'customers/',    // where you wanna post
            success: function(response) {
                var mystore = Ext.data.StoreManager.lookup('CustomerDataStore');
                var myData = Ext.JSON.decode(response.responseText);
                console.log(myData.toSource());
                mystore.loadData(myData);
            },
            jsonData: Ext.JSON.encode(queryform.getValues())
        });
    }
},

问题是我的网格没有显示回复的数据!我确定我回复的 JSON 格式没问题。我已经用 json 文件检查了它。还myData.toSource()返回我想要的 JSON 格式。我很困惑我做错了什么?

你能帮忙吗?

4

2 回答 2

8

我找到了解决方案,我不得不使用 loadRawData() 函数而不是 loadData()。

于 2012-06-17T07:00:43.940 回答
3

loadData()加载模型即记录,并且不解析内部的 JSON 数据。您需要在代理阅读器中指定您的 JSON 格式,然后当您调用时 store 会自动进行 Ajax 调用store.load()

于 2012-06-17T01:59:58.903 回答