PDA

View Full Version : creating store and model dynamically



anaP
19 Apr 2012, 10:38 PM
Hi all,
I am trying to create model and store dynamically and also a view using json.
below is the code to create store and model dynamically.

function modelFactory(name, fields) {return Ext.define(name, {
extend: 'Ext.data.Model',
config:{
fields: fields
} });
}


function storeFactory(storeName,modelName){
return Ext.define(storeName, {
extend: 'Ext.data.Store',
requires:[modelName],
config:{
model:modelName,
}
});


then I create a view from json document


modelFactory(panel.model,panel.modelFields);
storeFactory(mytaskGrid.store,panel.model);
tabPanel=viewport.insert(1,mytaskGrid);
tabPanel.setStore(tabPanelStore);



but it gives error as Uncaught TypeError: Cannot read property 'store' of undefined
Where am I going wrong?
Do I have to create instances of model and store?
If yes then how?

Thanks in advance.

YomeKitsuma
19 Apr 2012, 11:28 PM
Have you try to use string instead of "object" ?




modelFactory('panel.model', 'panel.modelFields'); // <- use string

storeFactory('mytaskGrid.store', 'panel.model'); // <- use string



Maybe this will work better since Ext.define uses a String as first parameter, and so !

anaP
22 Apr 2012, 7:37 PM
panel.model is a string value and panel.modelfields contains array of fields to create model.
How can I pass them as String?

vietits
22 Apr 2012, 7:47 PM
modelFactory(panel.model,panel.modelFields);
storeFactory(mytaskGrid.store,panel.model);
tabPanel=viewport.insert(1,mytaskGrid);
tabPanel.setStore(tabPanelStore);

but it gives error as Uncaught TypeError: Cannot read property 'store' of undefined
Where am I going wrong?
Do I have to create instances of model and store?
If yes then how?


What is mytaskGrid? What is mytaskGrid.store?
What is tabPanelStore? What is tabPanel.setStore()?
Do you know where is the point that the error happens?