I am trying to build a store that will generate a model based on data from the server Eg in the form of:
{success:true,data:[item1:{},item2{}...]}
Is there any way I can over write the model of a store?
This is what I have atm:
Ext.define('Tan.data.SimpleStore', {
extend: 'Ext.data.Store',
constructor: function (config) { //Not initComponent, thx for wasting an hour...
config=this.config||{};
Ext.define('Users', { //ext base example model.
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'string'},
]
});
config.proxy= {
type: 'ajax',
url : 'server.php?c=testFunction',
reader: {
type: 'json',
root: 'data'
}//Example return: {"success":true,"data":["0":1,"2":1,"3":1,"4":1]}
}
config.model='Users';//Store breaks without this :((
this.callParent([config]); //Proto It
this.load({ // watch for the load event and then manipulate
// ( or try to atleast ) the fields
callback: function(records,operation,success){
// As expected obj is correct
var obj=Ext.decode(operation.response.responseText);
//K now wtf. Have the data but....
Ext.ModelManager.unregister(this.config.model);
Ext.define(this.config.model, {
extend: 'Ext.data.Model'
,fields: Ext.Object.getKeys(obj.data)
,url : 'server.php?c=testFunction'
,reader: {
type: 'json',
root: 'data'
}
});//yay you over wrote the model, but meh, nothing
console.log(this); //Bleh 0 items in store.data
}
});
}
});
var s= Ext.create('Tan.data.SimpleStore');
s.load();
It appears that one must have a model declared when loading a store, so I just declare a crud one, with every intention of over writing it.
Theoretically I suppose it might work by doing a callback on an ext.Ajax call as a constructor function, but I am trying to avoid it.