当您尝试向ObjectController
添加绑定时,它不起作用。
App.FailController = Em.ObjectController.extend({
content: null,
myBinding: "App.router.myController" // <-- fails
});
Uncaught Error: assertion failed: Cannot delegate set('my', ) to the 'content' property of object proxy <.FailController:ember154>: its 'content' is undefined.
尝试将其添加到content
属性。
jsFiddle:demo
答案 0 :(得分:33)
信用卡至caligo-mentis {g}更多answered来自。{/ p>
ObjectProxy
委托set
对content
属性的任何调用,除非ObjectProxy
实例上存在具有相同名称的属性。简单的解决方案是在声明绑定之前定义具有所需名称的属性。
App.FailController = Em.ObjectController.extend({
my: null,
myBinding: "App.router.myController" // <-- works
});
jsFiddle:demo
答案 1 :(得分:4)
替代解决方案:
App.FailController = Em.ObjectController.extend({
content: Ember.Object.create(),
my: function() {
return App.router.myController;
}.property('App.router.myController')
});
或更好:
App.FailController = Em.ObjectController.extend({
content: Ember.Object.create(),
my: Ember.computed.alias('App.router.myController')
});