6
 self.resultList.forEach(function(item, index, enumerable){
                         console.log(self.resultList);
                         item.id=11;
                         item.get('id');
                     });

the item like this: enter image description here

if item.id = 11; the exception like this:

Assertion failed: You must use Ember.set() to access this property (of [object Object])

so item.get('id') or item.set('id',11)

the exception like this

Uncaught TypeError: Object # has no method 'get'

is this item not the Ember's Object?so what the item is?

could someone tell me how to change the 'itme.id's value..

Thanks a million

1
  • 1
    What is inside self.resultList? I think the array contains both plain JS Objects and Ember Objects. Commented Jul 31, 2013 at 17:16

2 Answers 2

21

You can use the Ember.set(yourObject, propertyName, value); and Ember.get(yourObject, propertyName); to safely set and get properties.

In your case:

self.resultList.forEach(function(item, index, enumerable) {
    Ember.set(item, "id", 11); 
    Ember.get(item, "id");
});
Sign up to request clarification or add additional context in comments.

2 Comments

the exception like this:You must use Ember.set() to access this property (of [object Object])
Strange, this error happens when you use obj.prop = value; instead of obj.set("prop", value); And in my aswer is used it.
0

In my case I did it in this way

//In my controller I've defined the array
displayInfoCheckboxes: [
    {
      turnover: {
        label: "Turnover",
        value: 1,
        propertyName: "turnover"
      }
    }, {
      pl: {
        label: "P&L",
        value: 1
      }
    }
]

//and in my handler I passed the full string path to the property in the set method

let displayInfoCheckboxes = this.get('displayInfoCheckboxes');
let controller = this;

displayInfoCheckboxes.forEach(function(items,index) {
  for (var key in items) {
    controller.set('displayInfoCheckboxes.' + index + '.' + key + '.value', false);
  }
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.