ExtJS store.loadData() 不加载 JSON 数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11066529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:23:36  来源:igfitidea点击:

ExtJS store.loadData() doesn't load the JSON data

ajaxjsongridextjs4

提问by Arya Mz

I am trying to load a JSON data which is replied back by an AJAX request to a grid. My store definition:

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

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)]);
    }
});

There is a button in my app which is defined as follows:

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

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())
        });
    }
},

The problem is that my grid doesn't show the replied data! I am sure that my replied JSON format is OK. I have checked it with a json file. also myData.toSource()returns my desired JSON format. I am pretty confused what I am doing wrong?

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

Could you plz help?

你能帮忙吗?

回答by Arya Mz

I found the solution, I had to use loadRawData() function instead of loadData().

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

回答by sha

loadData()loads models i.e. records, and doesn't parse JSON data inside. You need to specify your JSON format in proxy reader and then store will automatically do Ajax call when you call store.load()

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