Sencha Touch 2:“找不到指定的商店" [英] Sencha Touch 2: 'specified Store cannot be found'
问题描述
我正在尝试将JSON数据加载到NestedList中.我在/app/store/Exhibits.js
I'm trying to load JSON data into a NestedList. I have the following store file in /app/store/Exhibits.js
Ext.define('VisitTCMIndy.store.Exhibits',{
requires: ['VisitTCMIndy.model.Exhibit', 'Ext.data.proxy.JsonP'],
extend: 'Ext.data.TreeStore',
config: {
model: 'VisitTCMIndy.model.Exhibit',
proxy: {
type: 'jsonp',
url: 'http://www.example.com/explore.php',
reader: {
type: 'json',
rootPropery: 'children'
}
}
}
});
然后我在/app/view/Explore.js的以下视图中引用它
Then I reference it in the following view in /app/view/Explore.js
Ext.define('VisitTCMIndy.view.Explore', {
extend: 'Ext.Container',
requires: [
'Ext.data.TreeStore',
'Ext.dataview.NestedList',
'VisitTCMIndy.store.Exhibits',
],
xtype: 'explorecard',
config: {
iconCls: 'compass1',
title: 'Explore',
layout: 'fit',
items: [
{
xtype: 'titlebar',
docked: 'top',
title: 'Explore'
},
{
xtype: 'nestedlist',
fullscreen: true,
store: 'VisitTCMIndy.store.Exhibits',
detailCard: {
html: 'Explore Details'
},
listeners: {
leafitemtap: function(nestedList, list, index, target, record){
var detailCard = nestedList.getDetailCard();
detailCard.setHtml('Exhibit Title: '+ record.get('title'));
}
}
}
]
}
});
当我转到页面时,收到以下警告和一个空白列表:
I get the following warning and an empty list when I go to the page:
[WARN] [Ext.dataview.NestedList#applyStore]找不到指定的商店
[WARN][Ext.dataview.NestedList#applyStore] The specified Store cannot be found
在我生命中,我无法弄清楚自己在做错什么.
Fore the life of me, I can't figure out what I'm doing wrong.
推荐答案
好.原来,我必须在app.js文件中声明商店和模型.然后仅通过名称来引用我的商店,而无需其余类定义.因此,我将以下内容添加到我的app.js文件中:
Ok. Turns out I had to declare my store and model in my app.js file. Then refer to my store just by it's name without the rest of the class definition. So, I added the following to my app.js file:
models: ['Exhibit'],
stores: ['Exhibits'],
然后,这是我更新后的Explore.js视图文件.
Then, here's my updated Explore.js view file.
Ext.define('VisitTCMIndy.view.Explore', {
extend: 'Ext.Container',
requires: [
'Ext.data.TreeStore',
'Ext.dataview.NestedList',
'VisitTCMIndy.store.Exhibits',
],
xtype: 'explorecard',
config: {
iconCls: 'compass1',
title: 'Explore',
layout: 'vbox',
items: [
{
xtype: 'titlebar',
docked: 'top',
title: 'Explore'
},
{
xtype: 'nestedlist',
store: 'Exhibits',
title: 'Museum Levels',
displayField: 'title',
detailCard: {
html: 'Explore Details'
},
listeners: {
leafitemtap: function(nestedList, list, index, target, record){
var detailCard = nestedList.getDetailCard();
detailCard.setHtml('<div style="text-align:center;margin:.5em;"><img src="'+record.get('image')+'" alt="'+record.get('title')+'" />'+
'<p style="text-align:left;">'+record.get('text')+'</p></div>'
);
}
},
flex: 1
}
]
}
});
此外,请注意,我将布局从fit更改为vbox.我必须这样做,并给列表赋予1的弹性值,以使该列表现在实际显示它正在加载数据.
Also, notice I changed the layout from fit to vbox. I had to do this, and give the list a flex of 1 in order for the list to actually show now that it was loading the data.
这篇关于Sencha Touch 2:“找不到指定的商店"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!