【问题标题】:How to specify model name in store of an extjs 4?如何在 extjs 4 的存储中指定模型名称?
【发布时间】:2012-03-06 19:15:14
【问题描述】:

我在使用 extjs 4 的商店和模型时感到很沮丧。即使我在商店中指定了模型名称,我也会收到 Store defined with no model. You may have mistyped the model name. 错误。

这是我的代码:

Ext.define('iWork.store.CandidateDistribution', {
    extend: 'Ext.data.TreeStore',
    autoLoad: true,
    requires: 'iWork.model.Location',
    model: 'iWork.model.Location',

    proxy: {
        type: 'ajax',
        url: 'data/CandidateDistribution/CandidateCount.json',
        reader: {
            type: 'pentahoReader',
            root: 'resultset'
        }
    },
    listeners: {
        load: function(treeStore, currentNode, records, success, options) {
            console.log('in load listener');
            console.log(records);
        },
        beforeappend: function(currentNode, newNode, options) {
            console.log('in beforeAppend listener');

        },
        add: function(store, records, options) {
            console.log('in add listener');
        },
        beforeinsert: function(currentNode, newNode, option) {
            console.log('in beforeInsert listener');
        }
    }
});

我尝试将model: 'iWork.model.Location', 更改为model: 'Location'model: "Location"model: "iWork.model.Location",但仍然无法正常工作。

模型文件代码如下:

Ext.define('iWork.model.Location', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'name', type: 'string'},
        {name: 'candidateCount', type: 'string'}
    ]
});

引用该商店的树形面板代码如下:

Ext.define('iWork.view.CandidateDistribution', {
    extend: 'Ext.window.Window',
    alias: 'widget.candidateDistribution',
    require: ['iWork.store.CandidateDistribution'],
    layout: {
        type: 'hbox',
        align: 'stretch'
    },
    autoShow: true,

    initComponent: function() {
        this.items = [
            {
                xtype: 'treepanel',
                title: 'Location wise customer Distribution',
                store: 'iWork.store.CandidateDistribution',
                width: '25%',
                height: '100%',
                rootVisible: false
            }
        ];
        this.callParent(arguments);
    }
});

我尝试将store: 'iWork.store.CandidateDistribution' 更改为store: 'CandidateDistribution',但也无法正常工作。

如果我将store: 'iWork.store.CandidateDistribution' 更改为store: CandidateDistribution,我会在ext-debug.js (line 8002) 中收到以下错误

me.store is undefined
[Break On This Error] }, 

我无法找到我在哪里犯了错误。如果我错过了任何其他配置或我做错了什么,请告诉我。

谢谢!!


编辑 1:我的应用程序的 index.html 文件如下所示:

<html>
    <head>
        <title>iWork Dashboards</title>
        <link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css" />
        <script type="text/javascript" src="../extjs/ext-debug.js"></script>
    <script type="text/javascript" src="app/app.js"></script>
    <script type="text/javascript" src="app/PentahoReader.js"></script>
    </head>
    <body>
    </body>
</html>

【问题讨论】:

  • 模型文件是否加载正确?
  • 如何查看模型文件是否加载?
  • 相应的脚本必须存在于您的 html 的 &lt;head&gt; 中。您可以通过萤火虫或谷歌浏览器的开发工具检查它。仅当您将模型和商店保存在单独的文件中时,您才需要检查它。
  • @MoleculeMan,我自己添加了 index.html 文件的内容。
  • 您似乎已经发布了您的初始(静态)html 代码。它没有什么有趣的。您应该发布渲染的代码。页面加载后,从 firebug 的 html 选项卡中获取。

标签: model extjs4 store treepanel


【解决方案1】:

这是 Ext.tree.View 使用的 NodeStore 中的一个错误。当您使用树形面板时,您将始终看到这一点。

如果您在生成警告的行上中断,并查看堆栈,您会发现它位于 AbstractStore 的构造函数中,该构造函数已被 NodeStore 的构造函数调用,而 NodeStore 的构造函数又由 Tree View 的 initComponent 调用。

【讨论】:

  • 是的。我看到了堆栈跟踪和发生此错误的确切行。我想知道如何解决这个问题?
  • 这只是一个警告,所以我不会太担心。我不认为你可以在不修补 Ext 的情况下修复它。如果他们还没有关于它的错误报告,您可以提交一份。您也可以查看 4.1b2 并查看是否已修复。
猜你喜欢
  • 2011-09-17
  • 2012-07-11
  • 1970-01-01
  • 1970-01-01
  • 2011-10-01
  • 2010-12-11
  • 1970-01-01
  • 2015-05-20
  • 1970-01-01
相关资源
最近更新 更多