我使用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);