I am trying to get this code working in ember but it keeps giving me
“Uncaught TypeError: Object # has no method ‘get'” on line
this.get('element_id')[item.id] = true; why can’t it access the element_id hash?
function() {
return Ember.ArrayProxy.extend({
box: null,
content: [],
element_id: {},
init: function() {
this._super();
var items = this.get( 'box' ).getData();
if ( items.get( 'length' ) ) {
this.set( '[]', items );
};
// Initialize the hash
items.forEach(function(item) {
this.get('element_id')[item.id] = true;
});
}
});
}
);
When using the forEach method, you can pass a target object that will be set as
thison the context, as explained in the documentation:So your code should be now: