1

在尝试将本地存储实现到 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>'
       }
    ]

}

编辑:在切换到本地存储存储数据后,它也没有在视图上显示数据,这让我认为它实际上并没有切换。

4

1 回答 1

3

buyticketspanel是一个导航视图,因为它扩展Ext.navigation.View并且导航没有setStore方法,那个错误说的是完全相同的事情。

要清楚,您正在尝试将商店设置为列表,而不是导航视图。

这就是你在控制器中所做的

this.getBuyTicketsView().setStore(ticketStoreLocalStorage);

this.getBuyTicketsView()- 是给你导航视图,而不是列表。

您可以通过多种方式解决此问题。

解决方案 1

this.getBuyTicketsView().down('list').setStore(ticketStoreLocalStorage);

解决方案 2

将 itemId 提供给您的列表。

{
  xtype: 'list',
  itemId : 'buytick',  
  itemTpl: ['<div class="date-circle">{date}</div>'+
            '<div class="event-title">{title} - {location}</div>'+
            '<div class="buy-tickets-btn">Buy Tickets</div>'].join()
}

在控制器中执行此操作

this.getBuyTicketsView().getComponent('buytick').setStore(ticketStoreLocalStorage);

笔记

buytick作为 itemId 给了列表,所以我传入buytickgetComponent()

参考

导航

列表集存储

获取组件

于 2013-09-03T05:22:51.473 回答