-
16 May 2012 11:44 PM #1
access a model property from a field convert function
access a model property from a field convert function
i add a property to a model with default value 50 before it is instantiated like shown below.
i then want to access this property from a field convert function like below, however, this returns 'undefined' in the log. also when i hard code the property in the model, i am not able to access its value. Is there a way to do this? many thanks in advance for any suggestionsCode:var propertyValue = 50; this.myStore.getModel().addStatics({ modelProperty: propertyValue, }); this.myStore.load();
//i omitted the rest of the snippet for the ease of reading
Code:fields: [ {name: 'id'}, {name: 'distance', convert: function (value, record) { console.log(this.modelProperty) }, }, ],
-
17 May 2012 1:17 AM #2
Try this:-
instead ofCode:var propertyValue = 50; this.myStore.getModel().addStatics({ modelProperty: propertyValue, }); this.myStore.load();var propertyValue = 50;try
this.propertyValue = 50;
also remove ',' after propertyValue in addStatisticssword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
17 May 2012 5:08 AM #3
thanks sword-it for the suggestion. however the question was not so much about how can i put the property in the model, but rather how can i access it from the fields convert function? as i said also when i put the property hard coded into the model i am not able to access it form the fields convert function.
-
11 Sep 2012 6:09 AM #4
The static property or function will be added to the Model (class) is my guess, but not to instantiated objects of that model. So in your convert function you'd use it along the lines of
Code:function convert(v, record) { var adjustedValue = MyApp.model.MyClass.myStaticProperty + record.foo ; return adjustedValue; }


Reply With Quote