.get is not a function error


#1

At the time of Ember.Object.create , when i am trying to get the key value i am getting .get is not a function.


#2

Do you have an example?


#3
       obj.forEach(function(item) {
    	value:item.get("key");           
        });

For this code I am geeting .get not a function .


#4

Try to console.log(item) in forEach’s callback, then you will see what’s the problem…


#5

item.get("key") doesn’t work with native objects. It only works with instances of Ember.Object (and subclasses, of course).

Use the following syntax, that works for both Ember.Object instances and plain objects:

Ember.get(item, "key");

#6

A bit more explicit, code-wise:


var obj = Ember.Object.create();
obj.get('key.down.one.more.level'); // Works and returns undefined

var obj = {};
obj.get('key.down.one.more.level'); // TypeError: undefined is not a function