我使用jsonp代理使用商店填充listview,向我的服务器发送GET请求。当应用程序启动时,请求被发送,并且列表项与应答一样呈现。现在当我手动在我的数据库服务器中添加一个新项目并使用下面的控制器中显示的代码刷新列表并检查控制台中的存储对象时,我可以看到新创建的项目位于存储数据中。迄今如此好,一切都如预期。但是,新项目不在列表中刷新。奇怪的是,当我检查列表对象及其包含的商店对象时,新创建的项目不包括在内。但是,当我重新启动应用程序(而不是重新加载商店和刷新列表)新的新创建的项目出现在列表中。对我来说,似乎我有2个商店实例,一个与新数据(我用Ext.getStore检索)和一个没有(在ListView中的那个),我认为应该实际上是相同的。这怎么可能?下面我向你展示我是如何做到这一点的。任何帮助是极大的赞赏。我有两个同一商店的实例吗?
控制器
Ext.define('VB1.controller.ListController', {
extend: 'Ext.app.Controller',
config: {
refs: {
listView: 'listview',
refreshButtonTap: '#refreshbutton',
},
control: {
refreshButtonTap: {
onRefreshList: 'refreshList',
},
}
},
launch: function() {
this.callParent(arguments);
Ext.getStore('MyStore').addListener('load', 'recordLoaded', this);
},
refreshList: function() {
var loadedStore = Ext.getStore('MyStore').load();
console.log(loadedStore) //here the new item is included
},
recordLoaded: function() {
var list = this.getListView();
list.refresh();
console.log(list) //here the new item is not included in the store object inside
//listobject
}
});
商店
Ext.define('VB1.store.MyStore', {
extend: 'Ext.data.Store',
alias: 'widget.mystore',
config: {
model: 'VB1.model.MyModel',
autoLoad: true,
proxy: {
type: 'jsonp',
url : 'myUrl.js',
enablePagingParams: false,
reader: {
type: 'json',
rootProperty: 'array.resources'
},
},
},
});
列表视图
Ext.define('VB1.view.ListView', {
extend: 'Ext.dataview.List',
alias: 'widget.listview',
requires: [
'Ext.dataview.List',
],
scrollable: 'vertical',
config: {
loadingText: "loading...",
emptyText: '</pre><div class="notes-list-empty-text">No notes found.</div><pre>',
itemTpl: '</pre><div class="list-item-title">{title}</div><div class="list-item-narrative"><img src="{listlogo}"/></div><pre>',
},
listeners: {
itemtap: function(list, index, item, record) {
this.fireEvent('showDetails', record, this);
}
},
});
这是我怎么添加名单,包括商店视在应用程序启动
var listView = {
xtype: 'listview',
store: {xtype: 'mystore'},
}
Ext.Viewport.add(listView);