【发布时间】: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 的
<head>中。您可以通过萤火虫或谷歌浏览器的开发工具检查它。仅当您将模型和商店保存在单独的文件中时,您才需要检查它。 -
@MoleculeMan,我自己添加了 index.html 文件的内容。
-
您似乎已经发布了您的初始(静态)html 代码。它没有什么有趣的。您应该发布渲染的代码。页面加载后,从 firebug 的 html 选项卡中获取。
标签: model extjs4 store treepanel