开发者

Sencha touch one store instance for multiple stores

So I have two stores that use the exact same model, they are exactly the same in every way (except for their names of course). I want two different stores.

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',
      extraPa开发者_JS百科rams: {
        format: 'json'
    },
    reader: {
        root: 'query.results.item'
    }
}
});

My question is can I save space by getting rid of code and use only one store instance so I don't have to re-declare another new Ext.data.Store again?

something like:

store = new Ext.data.Store(...);
app.stores.newsFeed = store;
app.stores.eventsFeed = store;

I tried this before but both were assigned to the same store so when one was changed so was the other.


Just extend extJS component and you can get fast instances of your component:

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);
    }
});

And create as much independent instanses as you want:

app.stores.newsFeed = Ext.create(MyStore, {});
app.stores.eventsFeed = Ext.create(MyStore, {});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜