mardi 12 juillet 2016

Ember - computed property (which is an array) not taking updated value upon adding items to array

Am working on ember app (1.11) and having an issue with computed property not taking updated value when its updated in code . Code as below (have trimmed down, only showing relevant snippet).

Am showing a list of things on UI when iterating through "data" which is a computed property. Then I make a selection from drop down, I am sending a action, triggering that computed property and adding things to that list. When I do this once, I get all the updated list or iteration on UI, but when I do the selection again to increase the list/iteration, the computed property is taking the initial value of list, not the updated one, where I just added one more item, hence not showing correct details.

Its really driving me crazy, as I am not getting whats going wrong. I could not create a twiddle as well, as its a lot of code and got stuck in error in twiddle. Really need to solve this asap as have to meet the deadlines.

Parent Component- ehbs



Parent Component - js

list: function(){
  return this.get('arr')   //This arr comes from route/controller via query string in url
}.property('arr')

Pax Detail Component- ehbs




Pax Detail Component - js

countChanged: '',
actions: {
 changed: function(e){
  this.set('countChanged',e.target.value)
 }
},
data : function(){
  var arr = this.get('list')
  // doing lot to manipulation - constructing arr/object


if(this.get('countChanged')){
  arr.pushObject({}) // basically modifying the initial arr
  return arr
} else {
  return arr
}

}.property('list','countChanged')

Pax Select Component - ehbs

<select>
 <option>0</option>
 <option>1</option>
 <option>2</option>
</select>

Pax Select Component - js

change: function (e) {
   this.sendAction('action',e)
 }

Aucun commentaire:

Enregistrer un commentaire