Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set value of a object inside an Array in EmberJS?

Tags:

ember.js

In my ember application, I have an array of objects. I need to manipulate some object inside the array.

eg: Array: [{a:1}] then I need to change a to 2.

someArray: [{a: 1}],
didInsertElement() {
     var self = this;
     this.$('.some-element').on('scroll',function() {
         self.get('someArray')[0]['a'] = 2; // HOW TO DO THIS ?
     });
}

Also, I need the changes to be reflected in the view as well.

Note: Ember version 1.13

like image 524
Sudhir Shrestha Avatar asked Jun 02 '16 17:06

Sudhir Shrestha


2 Answers

var temp = self.get('someArray').objectAt(0);
Ember.set(temp, "a", 2);

This should work

like image 99
Prakash Avatar answered Oct 05 '22 23:10

Prakash


Ember.set(this.get('array').objectAt(index),'prop',value)
like image 37
Sahib Khan Avatar answered Oct 06 '22 01:10

Sahib Khan