我有一份表单名称和表单列表。当用户单击表单名称时,我只想显示与单击的名称匹配的表单。我在点击时传递了表单名称,但我无法弄清楚如何更新基于该表单显示的表单列表。如何在过滤器中更新模型?
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 :(得分: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>