2012-02-15 27 views
2

我试图根据我选择的标签控制器的内容来过滤我的文档控制器的内容。我不确定这是否是最好的解决方案,请随时提出替代方案。为什么下面的结果是“必须设置Ember.set()来访问这个属性”?

除了这种不确定性,任何人都可以解释为什么以下结果为assertion failed: Must use Ember.set() to access this property?特别是selectedTagsBinding: "App.selectedTagsController.content"是什么失败。

App = Ember.Application.create(); 

App.documentsController = Ember.ArrayProxy.create({ 
    content: [], 

    selectedTagsBinding: "App.selectedTagsController.content" 
}); 

App.selectedTagsController = Ember.ArrayProxy.create({ 
    content: [ new Ember.Object(), new Ember.Object() ] 
}); 

回答

2

更新:由于ud3323他回答说,这是不是一个错误,这个答案一直是我的App.set


知识之前被写这显然是绑定的错误。在App.documentsController之前移动App.selectedTagsController的声明。

App = Ember.Application.create(); 

App.selectedTagsController = Ember.ArrayProxy.create({ 
    content: [ new Ember.Object(), new Ember.Object() ] 
}); 

App.documentsController = Ember.ArrayProxy.create({ 
    content: [], 

    selectedTagsBinding: "App.selectedTagsController.content" 
}); 
4

其实这不是一个错误。你应该设置你的控制器是这样的:

App.set('documentsController', Ember.ArrayProxy.create({ 
    selectedTagsBinding: "App.selectedTagsController" 
})); 

App.set('selectedTagsController', Ember.ArrayProxy.create({ 
    content: [ 
     Ember.Object.create({ 
      name: "john" 
     }), Ember.Object.create({ 
      name: "sal" 
     }) 
    ] 
})); 

我写了一个简短的博客文章解释这里更详细的错误:http://ud3323.github.com/2012/02/15/ember-controllers-and-the-runloop.html

+0

感谢您的澄清! – pangratz 2012-02-16 14:28:00

+0

没问题。我实际上不得不在自己的代码中做同样的事情,有时候:) – 2012-02-16 14:48:09