2013-01-16 26 views
1
  • 我有一個激活addField和deleteField方法personArrayController
  • 我有(來自的CollectionView繼承)
  • 車把正在使連接的PersonCollectionView類:
    {{視圖PersonCollectionView contentBinding =「personArrayController」}}
  • 我需要在collectionView的每個視圖中都有一個按鈕,以允許刪除選定的元素。

子View模板需要調用personArrayController中的deleteField。目標被使用,否則路由器將被觸發。從的CollectionView模板操作上arrayController

正確顯示視圖的顯示,但是當我點擊「刪除」按鈕時,目標未找到(personArrayController未觸發)。

如何從我的模板視圖訪問personArrayController?
我想這是控制器訪問與目標=「view.content」 ...但它似乎是合乎邏輯的「view.content」是當前的數組元素,而不是arrayController ...

App.PersonCollectionView=Ember.CollectionView.extends({ 
itemViewClass: Ember.View.extend({ 
    template: Ember.Handlebars.compile(<button {{action deleteField view.content target="view.content"}}); 
    }) 
}) 

回答

1

您可以指定「控制器」作爲目標:

App.PersonCollectionView=Ember.CollectionView.extends({ 
itemViewClass: Ember.View.extend({ 
    template: Ember.Handlebars.compile(<button {{action deleteField view.content target="controller"}}); 
    }) 
}) 
+0

Tx爲您的答案。它的作品,但使其工作,我需要改變我的Handlebars調用{{查看PersonCollectionView contentBinding =「personArrayController」controllerBinding =「personArrayController」}}。有沒有更好的解決方案來避免填充contentBinding和controllerBinding屬性? – fvisticot

+0

我總是使用每個助手:{{#控制器中的每個項目}}。所以我不能幫你完成這個任務。 – mavilein