2014-07-12 61 views
0

我有一個表單名稱和窗體列表。當用戶點擊表單名稱時,我只想顯示與點擊名稱相匹配的表單。我點擊時傳遞了表單名稱,但我無法弄清楚如何更新基於此顯示的表單列表。你如何更新過濾器中的模型?從過濾器更新模型

JS

App.PatientFormsController = Ember.ArrayController.extend 
    actions: 
    filterForms: (name)-> 
     @get('model').filterBy('name', name) 

HTML

<h2>Form Types</h2> 
<div id='form-names'> 
    <ul> 
    {{#each formTypes}} 
     <li> 
     <a href="*" {{action 'filterForms' name on='click'}}>{{nameFormatted}}</a> 
     </li> 
    {{/each}} 
    </ul> 
</div> 

<h2>Forms</h2> 
<div id="patient-forms"> 
    {{#each}} 
    <b>{{name}}</b><br /> 
    {{/each}} 
</div> 

回答

0

我得到了它具有以下工作:

JS

App.PatientFormsController = Ember.ArrayController.extend 
    init: -> @set 'filteredForms', @get('model') 
    actions: 
    filterForms: (name)-> 
     @set 'filteredForms', @get('model').filterBy('name', name) 

HTML

<h2>Form Types</h2> 
<div id='form-names'> 
    <ul> 
    {{#each formTypes}} 
     <li> 
     <a href="*" {{action 'filterForms' name on='click'}}>{{nameFormatted}}</a> 
     </li> 
    {{/each}} 
    </ul> 
</div> 

<h2>Forms</h2> 
<div id="patient-forms"> 
    {{#each filteredForms}} 
    <b>{{name}}</b><br /> 
    {{/each}} 
</div>