-
18 Mar 2012 11:48 PM #1
Ext.data.Model#setFields not Working as Expected
Ext.data.Model#setFields not Working as Expected
Documentation states that one can modify the fields for every instal of a Model with code such as:
A field named bar is not added to the next instance.
Except if you look at the source in #updateFields, the fieldsCollection is just a local variable.Code:Ext.define('TestModel', { extend: 'Ext.data.Model', config: { fields: [ { name: 'foo' } ] } }); (Ext.create('TestModel')).setFields([ { name: 'bar' } ]); console.log((Ext.create('TestModel')).getFields());
-
19 Mar 2012 9:04 AM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,651
- Vote Rating
- 14
Thank you for the report.
-
19 Mar 2012 9:25 AM #3
If you have a work around for this, it'd be much appreciated. I've not had time yet to investigate this further.
Thanks!
-
28 Mar 2012 8:00 AM #4Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Haarlem, Netherlands
- Posts
- 1,235
- Vote Rating
- 4
Hi wprater,
Sorry for the delayed reply. I feel like the documentation should be improved to explain this, but if you set the fields on a model instance, it should only be reflected on that particular instance. If you want to change the fields for every new instance created of a Model, you should call the method on the Model class. In your example if you change it to the following, it will achieve what you are trying to do.
Hope this solves your problem.Code:Ext.define('TestModel', { extend: 'Ext.data.Model', config: { fields: [{ name: 'foo' }] } }); Ext.setup({ onReady: function() { TestModel.setFields([{ name: 'bar' }]); console.log((Ext.create('TestModel')).getFields()); } });
Best,
Tommy
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote
