Sencha触摸多个商店的一个商店实例
问题描述:
因此,我有两个商店使用完全相同的模型,它们在各方面都完全相同(除了它们的名称当然)。我想要两个不同的商店。Sencha触摸多个商店的一个商店实例
app.stores.newsFeed = new Ext.data.Store({
model: 'app.models.feedData',
proxy: {
type: 'scripttag',
url: 'http://query.yahooapis.com/v1/public/yql',
extraParams: {
format: 'json'
},
reader: {
root: 'query.results.item'
}
}
});
app.stores.eventsFeed = new Ext.data.Store({
model: 'app.models.feedData',
proxy: {
type: 'scripttag',
url: 'http://query.yahooapis.com/v1/public/yql',
extraParams: {
format: 'json'
},
reader: {
root: 'query.results.item'
}
}
});
我的问题是,我可以节省空间,通过摆脱代码和只使用一个存储实例,所以我不必再重新申报另一个新Ext.data.Store?
类似:
store = new Ext.data.Store(...);
app.stores.newsFeed = store;
app.stores.eventsFeed = store;
我以前试过,但都被分配到同一家商店所以当一个人被更改,因此被对方。
答
只是延长ExtJS的组件,你可以得到你的组件快速实例:
MyStore = Ext.extend(Ext.data.Store, {
constructor : function(config) {
config = Ext.apply({
model: 'app.models.feedData',
proxy: {
type: 'scripttag',
url: 'http://query.yahooapis.com/v1/public/yql',
extraParams: {
format: 'json'
},
reader: {
root: 'query.results.item'
}
}
}, config);
MyStore.superclass.constructor.call(this, config);
},
onDestroy : function(config) {
MyStore.superclass.onDestroy.apply(this, arguments);
}
});
并根据需要创建尽可能多的独立instanses:
app.stores.newsFeed = Ext.create(MyStore, {});
app.stores.eventsFeed = Ext.create(MyStore, {});
这正是我需要谢谢。但是我不能让Ext.Create为我正确工作(如果一直想让我注册一个xtype)。我用app.stores.newsFeed =新的MyStore(),它的作用就像一个魅力。 – ericbowden