PDA

View Full Version : Redfining models



ldm314
8 Feb 2011, 5:56 PM
I have a model that I want to change the set of fields that are in the model later. For example, my backend data may return a new field on a later call so I want to change the model to have this new field.

My current code:



Ext.regModel('SingleContact', {
fields: ['name','phone','email','id', 'account_id']
});

contact.SingleStore = new Ext.data.JsonStore({
autoDestroy: true,
storeId: 'singleContactStore',

model: 'SingleContact',
sorters: 'name',
getGroupString : function(record) {
return record.get('name')[0];
},
proxy: {
type: 'ajax',
url: '/app/Scontact/json',
reader: {
type: 'json',
root: 'contacts',
idProperty: 'id'
}
},
idProperty: 'id',
listeners: {
load: {
fn: function(store,array,success) {
contact.DetailForm.user = store.data.items[0];
contact.FormPanel.loadModel(contact.DetailForm.user);
contact.Page.setActiveItem(1);
}
}
}
});


It works fine if I call Ext.regModel with the new fields, and then create an entirely new store in contact.SingleStore. Is there a cleaner method where I can make a call to reload the model on the existing data store without having to create a new object?

ldm314
22 Mar 2011, 8:58 AM
Any ideas on this? I am running into other side effects having to do this.

The app I am doing has a dynamic list of fields that may change based on what the back end data source sends. Users can define custom fields that the fields on the app then need to be updated.

I definitely would appreciate some guidance on how to do this properly, or a pointer to something I can read to help me understand how to do it.