2012-04-18 79 views
0

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

回答

1

我刚刚发现问题是什么。首先,商店被实例化了2次,正如我怀疑的那样。显然有一次是由应用程序,另一次是由视图。所以我结束了两个商店。因为我没有设置storeID,所以商店通过两个唯一的ID来标识,这两个ID基于我在商店的别名配置中给出的xtype名称。

我分辨和记录在控制器像下面有ID前的MyStore-1

var loadedStore = Ext.getStore('MyStore').load(); 
     console.log(loadedStore) //here the new item was included 

和列表视图对象内的商店的商店得到了ID EXT-的MyStore-2

var list = this.getListView(); 
    console.log(list._store); //here the new item was not included 

在我看来,改变了钻孔问题的原因是我在商店中添加了storeId。在那之后,我仍然有两家商店,但是有着同样的商店标识(但带有不同的独特或可观察的标识)。好的新功能是现在这个新的商品被包含在两个商店实例中。我也能够通过在商品列表视图中没有实例化商店的xtype而通过storeID引用它来摆脱第二个商店实例。现在一切都按原样进行。感谢任何看着这个的人。我希望这能帮助发现类似问题的人。

相关问题