在尝试将本地存储实现到 Sencha Touch 2 应用程序时遇到一个小问题。我让它从我的外部存储中查找数据,但之后我的控制器中的函数应该将视图存储切换到我创建的本地存储存储,一旦它最初找到并存储数据。
我有一个要更新存储的视图的引用,但是当我尝试使用 setStore 更新它时,它给了我以下错误:
未捕获的类型错误:对象 [object Object] 没有方法“setStore”
任何帮助将不胜感激。这是代码:
控制器:扩展:'Ext.app.Controller',
config: {
refs: {
buyTicketsView: 'buyticketspanel'
},
control: {
'buyticketspanel list': {
itemsingletap: 'buytickets'
},
buyTicketsView : {
show: 'loadTickets'
}
}
},
buytickets: function(list, idx, el, record) {
Ext.Msg.confirm('External Link', 'Open external link?', function(result){
if (result == 'yes') {
//window.location = 'http://www.youtube.com/watch?v=' + record.get('id');
window.location = 'http://' + record.get('link');
}
});
},
loadTickets: function() {
//set up refs to the two stores
var ticketStore = Ext.getStore('ticketStore');
var ticketStoreLocalStorage= Ext.getStore('buyTicketsLocalStorage');
//load the localStorage store
ticketStoreLocalStorage.load();
// check if localStorage contains data
if ((ticketStoreLocalStorage.getCount()) == 0) {
// nothing found so we need to load the data from external source
console.log('localStorage data not found');
//hand off to onMarkerStoreLoad function (below)
ticketStore.on({
load: 'onTicketStoreLoad',
scope: this
});
//call load to trigger above
ticketStore.load();
} else {
// we are ok, just print some debug
console.log('localStorage data found');
console.log('localStorage count:' + ticketStoreLocalStorage.getCount());
}
//finally set the list's store to localStorage
console.log(this.getBuyTicketsView());
//THIS LINE IS THE ONE THAT IS FAILING
this.getBuyTicketsView().setStore(ticketStoreLocalStorage);
},
onTicketStoreLoad: function() {
//set up refs
var ticketStoreLocalStorage= Ext.getStore('buyTicketsLocalStorage');
var ticketStore = Ext.getStore('ticketStore');
//loop through each data item and add to localStorage
ticketStore.each(function(item){
ticketStoreLocalStorage.add(item);
});
ticketStoreLocalStorage.sync();
}
看法:
extend: 'Ext.navigation.View',
xtype: 'buyticketspanel',
config: {
navigationBar: {
hidden: true
},
title: 'Buy Tickets',
iconCls: 'MyScheduleIcon nav-schedule',
items: [
{
docked: 'top',
xtype: 'toolbar',
title: '<span class="logo"></span>'
},
{
xtype: 'list',
itemTpl: '<div class="date-circle">{date}</div><div class="event-title">{title} - {location}</div><div class="buy-tickets-btn">Buy Tickets</div>'
}
]
}
编辑:在切换到本地存储存储数据后,它也没有在视图上显示数据,这让我认为它实际上并没有切换。