2015-04-02 56 views
2

組件是否有任何方法來監聽或觀察所產生內容中的更改?觀察/檢測Ember組件的變化{{yield}}塊

我有一個作爲isotope.js包裝的組件,希望能夠在包裝內容發生變化的情況下調用一些必要的清理同位素方法(例如.isotope('layout'))(例如通過過濾)。

我已經能夠通過觀察控制器屬性來做一些與View類似的事情,但是如果可能的話,我想盡量減少耦合。

回答

0

那麼,我不知道你想要做什麼,也沒有我使用過isotope.js。但是,我可以告訴你。該{{yield}}助手調用此函數:

_yield: function(context, options, morph, blockArguments) { 
     var view = options.data.view; 
     var parentView = this._parentView; 
     var template = get(this, 'template'); 

     if (template) { 
      Ember.assert("A Component must have a parent view in order to yield.", parentView); 

      view.appendChild(Ember.View, { 
       isVirtual: true, 
       tagName: '', 
       template: template, 
       _blockArguments: blockArguments, 
       _contextView: parentView, 
       _morph: morph, 
       context: get(parentView, 'context'), 
       controller: get(parentView, 'controller') 
       //expose parent to children components? 
      }); 
     } 
} 

在理論上這意味着你可能暴露的句柄,你的子組件設置父組件的屬性。這明顯地結合了這兩個組件。您還可以讓孩子和父母都將「包裝內容」作爲屬性,以便您可以在兩處觀察和操作。我用這兩種方法取得了巨大的成功。我使用的是由背景決定的