2012-02-15 23 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