【问题标题】:loading data to store but no data visible in grid加载要存储的数据,但在网格中看不到数据
【发布时间】:2013-08-05 11:26:47
【问题描述】:

所以我将 json 加载到商店,但网格中没有可见的数据。我究竟做错了什么?这是网格:

            {
                xtype: 'gridpanel',
                title: 'Clients List',

                store: Ext.create('Ext.data.Store', {

                    model: 'app.model.modelClients',

                    proxy: Ext.create('Ext.data.HttpProxy', {
                        type: 'ajax',
                        headers: { 'Accept': 'application/json' },
                        url: 'client.php',
                        noCache: false,
                        startParam: undefined,
                        filterParam: undefined,
                        limitParam: undefined,
                        pageParam: undefined
                    }),

                    reader: new Ext.data.JsonReader({
                        root: 'records',
                        id: 'id',
                        fields: ['first_name', 'last_name', 'phone']
                    }),

                    listeners: {
                        load: function (self, records, successful, eOpts) {
                            var fields = records[0].fields;
                            console.log(fields.getAt(0));
                        }
                    },

                    autoLoad: true
                }),

                flex: '1',
                columns: [
                    { text: 'Name', dataIndex: 'first_name' },
                    { text: 'Last Name', dataIndex: 'last_name' },
                    { text: 'Phone', dataIndex: 'phone' }                        
                ]
            }

【问题讨论】:

  • 服务器响应什么?您是否看到,在开发人员工具中,请求实际触发并返回您期望的响应(以及 200 http 状态代码)? ...而且我认为您尝试在负载侦听器中调试的是记录 [0].data,而不是字段。
  • 是的。反应当然没问题。
  • 我正在尝试调试为什么加载到商店的数据不会显示在网格中。谢谢,我认为您对 records[0].data 的看法是正确的
  • 只是一个猜测,但您可能有类似 { data: {name: '',... 在这种情况下,您需要从您的代理中指定一个阅读器并拥有 root: 'data'或类似的东西
  • 没有。不是这样的

标签: javascript ajax json http extjs


【解决方案1】:

啊。您的读者处于错误的水平。它是代理的一部分

 proxy: {
    type: "ajax",
    url: "...",  
    reader: {

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 2013-04-25
    • 1970-01-01
    • 2023-03-27
    • 2014-02-15
    • 1970-01-01
    相关资源
    最近更新 更多