I'm using Sencha touch 2. I have store that load from existing js object:
Ext.define('majestic.store.Dataset', {
extend : 'Ext.data.Store',
requires : [
'majestic.model.Dataset',
'majestic.util.config.ConfigurationManager'
],
config : {
model : 'majestic.model.Dataset',
type: 'memory',
reader: 'json',
autoLoad : true,
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty : 'datasets'
}
}
},
constructor: function(config) {
this.callParent(arguments);
this.applyData(majestic.util.config.ConfigurationManager.getConfig());
}
});
Model:
Ext.define('majestic.model.Dataset', {
extend : 'Ext.data.Model',
config : {
fields : [
'title'
],
associations: [
{type: 'hasMany', model: 'Layer', name: 'layers'}
]
}
});
And view:
Ext.define('majestic.view.LayerList', {
requires: ['majestic.store.Dataset'],
extend: 'Ext.dataview.List',
config:{
store: 'Dataset',
itemTpl: '<div>{id} is {title}</div>',
itemSelector: "div"
}
});
After looking at Data view in Sencha touch i've added autoLoad and itemSelector, still no luck.
Though running
new majestic.store.Dataset().each(function(i) {console.log(i)});
outputs list of objects with filled data attributes.
UPDATE
I agree with @fbrandel that first option is how it should work, but after reading ST source i've figured out that store parameter of dataview is interpreted as:
- store object
- json store notation like in first example here
- name of already created store which can be resolved using StoreManager.lookup
So I ended up with:
- Leaving
store:'Dataset'
in View - Adding
storeId : "Dataset"
to store, so it can be resolved by StoreManager - Adding
stores: ['Dataset']
which caused creation ofmajestic.store.Dataset
and registering it in StoreManager
P.S. It also could be done using this.setStore(new majestic.store.Dataset())
in initialization
method of GridView, but I prefer declarative way where posible