按照Ember上的示例在我的 ArrayController 定义中设置 itemController 会导致阻塞错误消息:
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()
});
我发现解决这个问题的唯一方法是......
1)在#each处理程序(jsfiddle)中传递itemController:
{{#each addresses itemController="address"}}
<li>{{line1}}, {{city}}</li>
{{/each}}
...或者...
2) 向 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'})
]
});
这两种解决方案都让人觉得很笨拙而且非常错误。在 ArrayController 本身中设置 itemController 我做错了什么?