Model view controller EmberJS 2.x,通过操作从存储中重新调用或过滤记录
考虑js文件中的以下代码:Model view controller EmberJS 2.x,通过操作从存储中重新调用或过滤记录,model-view-controller,ember.js,ember-data,Model View Controller,Ember.js,Ember Data,考虑js文件中的以下代码: App.ApplicationRoute = Ember.Route.extend({ model: function(){ return this.store.findAll('team'); } }); 在html文件中,您可能有如下内容: {{#each model as |team|}} <ul> <li>{{team.name}}</li> <li>{{team
App.ApplicationRoute = Ember.Route.extend({
model: function(){
return this.store.findAll('team');
}
});
在html文件中,您可能有如下内容:
{{#each model as |team|}}
<ul>
<li>{{team.name}}</li>
<li>{{team.email}}</li>
<li>{{team.state}}</li>
<li>{{team.position}}</li>
</ul><br>___<br>
{{/each}}
{{{#每个模型作为|团队}
- {{team.name}
- {{team.email}
- {{team.state}
- {{team.position}
\uuuuuuuuuuuuu
{{/每个}}
结果会是
- 鲍勃·史密斯
- 鲍勃。smith@bobsmithinc.com
- 纽约
- 领导
- 简·史密斯
- 简。smith@janesmithinc.com
- 纽约
- 财务
- 无名氏
- 约翰。doe@janesmithinc.com
- CA
- 支持
我猜这是通过一个动作在控制器中发生的?我只是不明白如何抓取商店数据(没有网络请求)并利用或过滤已经存在的数据。我知道您可以使用“peek”,但我不确定如何显示数据。要对模型中的数据进行排序您必须像这样在控制器中创建新的计算属性
sortedList: Ember.computed.sort('model', 'sortProperties'),
sortProperties: ['name:desc'], // properties to use for sorting
然后在模板中可以使用它
{{#each sortedList as |team|}}
因此,通过将
sortProperties
修改为,例如[state:asc]
,您可以更改操作处理程序中的排序顺序来对模型中的数据进行排序,您必须像这样在控制器中创建新的计算属性
sortedList: Ember.computed.sort('model', 'sortProperties'),
sortProperties: ['name:desc'], // properties to use for sorting
然后在模板中可以使用它
{{#each sortedList as |team|}}
因此,通过将
sortProperties
修改为例如[state:asc]
,您可以更改排序顺序,排序顺序可以在处理程序中执行一个快速问题。。。。我如何让它充满活力,这样我才能付诸行动?我不知道如何在操作中传入sortedList或sortProperties,除非它只是嵌套在操作中?一个简单的问题。。。。我如何让它充满活力,这样我才能付诸行动?我不知道如何在操作中传入sortedList或sortProperties,除非它只是嵌套在操作中?