【问题标题】:ExtJS Store reader.read not foundExtJS 商店 reader.read 未找到
【发布时间】:2012-06-28 15:39:19
【问题描述】:

我有这家店:

Ext.define("App.store.units.MyStore", {

    extend:'Ext.data.Store',
    requires: "App.model.units.MyModel",

    model: "App.model.units.MyModel",
    id:'myStore',
    pageSize:10,
    proxy: {
        type: 'jsonp',
        url: urls.MyUrl+"/search",
        limitParam: 'undefined',
        startParam: 'offSet',
        pageParam: 'undefined',
        extraParams: {
            searchString: 'a'
        },
        reader: {
            root: 'results.results',
            totalProperty: 'numFound',
            type: 'json'
        }
    }
});

请求有效,我得到了预期的响应。

由于某种原因,现在我在浏览器中得到了这个:

reader.read is not a function

我不明白问题出在哪里,因为昨天一切正常(我知道这听起来如何,但我真的不知道有什么不同)。

有什么可能有帮助的建议吗?

编辑这也是模型的(动态)定义:

function(config){
    try{
        console.log("INIT MODEL");
    Ext.define("App.model.units.MyModel", {
        extend: 'Ext.data.Model',
        fields: config
    });
    } catch(err){
        console.log("Error");
    }
}

此函数在创建商店之前运行,config 对象是 {name: 'value'} 项目中的 array

我不知道出了什么问题。现在一切似乎在 Firefox 中运行良好,但 IE8 仍然存在该错误(阅读器中带有 type:'json' 的事件)。我认为阅读器在 IE8 中没有正确安装,但我无法检查它,因为对象没有正确显示在其控制台中(或者我没有这样做的知识)。为什么没有按应有的方式运行相同的 javascript 代码?

以后编辑 出于某种原因,我得到reader 只是有时创建。这就是问题。有时它只是一个对象,而不是需要的reader。这也发生在 Firefox 中。似乎没有任何模式。

【问题讨论】:

  • 这在我看来像是一个与模型相关的问题。尝试用简单的fields: [...] 声明替换model: 引用,并查看存储是否成功加载。另外,请将您的代码发布为App.model.units.MyModel
  • @VasiliyFaronov 这与模型无关。模型是动态定义的,接收到的字段属于模型中定义的字段。我对此非常肯定。在我做了几次refresh 并更改了一些console.log() 之后,Firefox 中的一切似乎都很好(但我仍然不知道为什么)。 IE8 仍然显示类似的错误。还有其他建议吗?
  • 我只是问,因为我在 JSFiddle 中尝试过你的代码,它给了我同样的错误,直到我输入 fields 声明。从我自己的经历中,我依稀记得类似的事情。问题可能不在于模型本身,而在于读者如何连接到它。除此之外,请尝试打开您商店的 beforeload 并手动检查 store.getProxy().getReader() 以查看那里是否有什么有趣的地方。
  • 也可以尝试直接在您的阅读器上设置model(除了商店),以防万一。
  • 拼写错误? requires 而不是 require?

标签: javascript extjs jsonp extjs4.1


【解决方案1】:

我有非常相似的问题。这就是帮助:

Ext.require('App.model.units.MyModel');
//or any other model you use in your store

把它放在之前你创建你的商店,它的工作原理!

【讨论】:

    【解决方案2】:

    需要的配置是一个数组,如 ExtJS 文档中所述:

    http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Class-cfg-requires

    【讨论】:

      【解决方案3】:

      删除商店字段时出现此错误。我有这个网格......

      网格

                  columns: [
                      {header: "Status", width: 75, sortable: true, dataIndex: 'partystatus'},
                      {header: "Name", width: 160, sortable: true, dataIndex: 'partyname'},
                      {header: "Fathersname", width: 75, sortable: true, dataIndex: 'fathersname'},
                      {header: "Grandfather", width: 75, sortable: true, dataIndex: 'grandfather'},
                      {header: "Type", width: 75, sortable: true, dataIndex: 'partytype'}
                  ],
      

      以及以下商店:

      商店

          fields: [
              {name: 'firstName', type: 'string'},
              {name: 'name', type: 'string'},
              {name: 'age', type: 'int'},
              {name: 'eyeColor', type: 'string'}
          ],
      

      我只是删除了商店字段,认为它们是多余的,但我得到了那个错误。

      【讨论】:

        猜你喜欢
        • 2019-12-21
        • 1970-01-01
        • 1970-01-01
        • 2012-10-01
        • 2014-03-11
        • 2011-11-18
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        相关资源
        最近更新 更多