2013-02-11 71 views
0

我想創建一個專門的選擇控件視圖,它應該簡單地添加一些功能。爲了簡單起見,我只希望能夠添加標題。使用參數創建可重複使用的Ember.Select控件

控制/查看:

window.App.ControlsSelectView = Ember.View.extend({ 
    templateName: 'controls/SelectView', 
    title:"Hello Control", 
    contentBinding: null 
}); 

匹配的html:

<div class="sub_heading"> 
    <h2>{{title}}</h2> 
</div> 
<div class="inner_12 input_wrapper custom_select"> 
    {{view Ember.Select 
      multiple="true" 
      contentBinding= "contentBinding" // how to pass parameters through? 
      selectionBinding="content.tempSelectedFunctions" 
      optionLabelPath="content.displayname" 
      optionValuePath="content.id" 
    }} 
</div> 

用法應該是這樣的:

{{ view App.ControlsSelectView 
    contentBinding="content.data.responsibilities" 
    selectionBinding="content.tempSelectedFunctions" 
    title="content.responsibilitTitle" 
}} 

問題是,這是行不通的像那樣。上述可能嗎?或者有更好的模式來創建簡單的可重新控制?

+0

我不知道你會以正確的方式。你寧願子類'Ember.Select'類.. – 2013-02-12 13:38:12

+0

我實際上它得到工作。看到我的答案。 – AyKarsi 2013-02-13 13:12:00

回答

1

這篇文章幫助我在正確的軌道上:

get content in view from ContentBinding

我需要view.propertyname

引用視圖參數工作液控制視圖的HTML中:

HTML:

<div class="sub_heading"> 
    <h2>{{view.title}}</h2> 
</div> 
{{#if view.content}} 
    <div class="inner_12 input_wrapper custom_select"> 
     {{view Ember.Select 
       multiple="view.multiple" 
       contentBinding= "view.content" 
       selectionBinding="view.selection" 
       optionLabelPathBinding="view.optionLabelPath" 
       optionValuePathBinding="view.optionValuePath" 
     }} 
    </div> 
{{/if}} 

ControlView

window.App.ControlsSelectView = Ember.View.extend({ 
    templateName: 'controls/SelectView' 

}); 

用法:

{{view App.ControlsSelectView 
     title = "Function" 
     multiple="true" 
     contentBinding="content.data.functions" 
     selectionBinding="content.tempSelectedFunctions" 
     optionLabelPath="content.displayname" 
     optionValuePath="content.id" 

}} 
相關問題