json - Ember #<Object> has no method 'set' -
i'm extracting json data in routes follows:
app.collectionroute = ember.route.extend({ setupcontroller: function(controller, model){ $.getjson('../returnitems.json', function(data){ controller.set('returnitems', data); }) } });
which gives me object can iterate on in template with:
{{#each destination in controller.returnitems}}
now want remove via controller following code:
this.get('controllers.collection').get('returnitems')[returnindex].set('hasitems', false);
which gives following error:
uncaught typeerror: object #<object> has no method 'set'
but when use: this.get('controllers.collection').get('returnitems')[returnindex].hasitems = false
it tells me use , set?!
you shouldn't doing ajax calls in setupcontroller
hook. should use model
, aftermodel
hooks ember waits until promise succeeds before transitioning route.
now, can't call set
method because $.getjson
returns array of plain old javascript objects instead of array of ember.object
s you're expecting.
instead you'd this:
app.collectionroute = ember.route.extend({ aftermodel: function(controller, model) { var self = this; return $.getjson('../returnitems.json', function(data_items){ var items = []; (var = 0; < data_items.length; i++) { items.push(ember.object.create(data_items[i])); } self.set('returnitems', items); }); }, setupcontroller: function (controller, model) { controller.set('returnitems', this.get('returnitems')); } });
then you'd able to:
this.get('controllers.collection').get('returnitems').objectat(returnindex).set('hasitems', false);
i hope helps you!
Comments
Post a Comment