PDA

View Full Version : Dynamic Model



rahul.aggarwal
1 Jul 2014, 10:54 PM
I want to make an Ajax request before the store config to load its model dynamically. But every time the config method is compiled first.Crm.app.x is my global variable. Tell me the right way to do so.

Ext.Ajax.request({
url: Crm.app.storeUrl+'(\'Dialogue\')/fields',
headers:{
'Accept':'application/json;odata=verbose'
},
success: function(response) {
try{
var resp = response.responseText;
if(resp) {
var data = Ext.JSON.decode(resp);
fields = [{
name: 'id'
}];
for(var i = 0, len = data.d.results.length; i < len; i++){
//Crm.app.DialogueFields.push({name:data.d.results[i].InternalName});
fields[i+1] = {
name: data.d.results[i].InternalName
}

}
Crm.app.x=Ext.define('Crm.model.DialogueModel', {extend: 'Ext.data.Model',fields:fields});

alert(fields[1].name);
alert(Crm.app.x);
}
}catch(e){
console.error(e);
}
},
failure: function(e){
console.error(e);
}
});
Ext.define('Crm.store.DialogueStore',{

extend: 'Ext.data.Store',

requires: [
// 'Crm.model.DialogueModel',
'Ext.data.proxy.Ajax',
'Ext.data.reader.Xml'

],

config: {
autoLoad: true,
autoSync: true,
model: Crm.app.x,
storeId: 'DialogueStore',
proxy: {
type: 'rest',
url: Crm.app.storeUrl+'(\'Dialogue\')/items',
reader: {
type: 'xml',
record: 'entry'
}
}
}
});

mitchellsimoens
16 Jul 2014, 9:53 AM
Why not return the metaData in your response and the store will then create the model for you?