ember.js - Ember: Using itemController in ArrayController doesn't work (TypeError: Cannot call method 'lookup' of null ) -
following examples on ember setting itemcontroller in arraycontroller definition causes blocking error message:
typeerror: cannot call method 'lookup' of null jsfiddle: http://jsfiddle.net/jgillick/m4bvv/
// addresses array controller app.addressescontroller = ember.arraycontroller.extend({ itemcontroller: 'address' }); // address object controller app.addresscontroller = ember.objectcontroller.extend({ city: function(){ return "san francisco"; }.property() }); the way have found fix either...
1) pass itemcontroller in #each handler (jsfiddle):
{{#each addresses itemcontroller="address"}} <li>{{line1}}, {{city}}</li> {{/each}} ...or...
2) add container property arraycontroller (jsfiddle):
var addresses = app.addressescontroller.create({ container: indexcontroller.get('container'), content: [ app.address.create({'line1': '700 hansen wy'}), app.address.create({'line1': '900 hansen wy'}) ] }); both of these solutions feel hacky , wrong. doing wrong setting itemcontroller in arraycontroller itself?
the itemcontroller controller , each view, don't have relation. although same thing: wraps object in specified controller.
your first implementation throws cannot call method 'lookup' of null, because container instance of addressescontroller null. container setup when create controller other container. abstracted you, if use:
this.controllerfor('addresses') instead of
app.addressescontroller.create ... so work http://jsfiddle.net/marciojunior/graa5/
1) pass itemcontroller in #each handler
like said before, itemcontroller controller, , each helper, don't have relation. can mix him.
{{#each addresses itemcontroller="address"}} <li>{{line1}}, {{city}}</li> {{/each}} see in action http://jsfiddle.net/marciojunior/spa9q/
2) add container property arraycontroller
this work because of previous explanation,
because
containerinstance ofaddressescontrollernull
finishing @colymba example works, because before of setupcontroller:
setupcontroller: function(controller, model){ controller.set('content', model); } ember provide controller in hook using controllerfor, container present in generated controller too.
Comments
Post a Comment