EmberJS - 如何过滤数组并通过路由器将其传递给模板 [英] EmberJS - How to filter array and pass it to template via router

查看:70
本文介绍了EmberJS - 如何过滤数组并通过路由器将其传递给模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看到这个 jsFiddle

我有这样的数组。

App.Fields = [{id: "Gender", desc: "Male", key: "M"}, 
                  {id: "Gender", desc: "Female", key: "F"}, 
                  {id: "Martial Status", desc: "Single", key: "S"}, 
                  {id: "Martial Status", desc: "Married", key: "M"}];   

当我的路由器执行时,我想通过基于过滤的数组的model.id。以下是我的路由器。

While my router executes i want to pass filtered array based model.id. Below is my router.

App.FieldRoute = Ember.Route.extend({
  setupController: function(controller, Field) {
    controller.set('model', App.Fields);
  }
});

当用户点击Gender时,我想从上述数组过滤id =Gender的对象。

When user clicks "Gender" i want to filter objects having id = "Gender" from the above array.


FYI:model.id将给出性别。

FYI: model.id will give "Gender".


推荐答案

您还可以使用.filterProperty()返回匹配属性的数组

You could also use .filterProperty() which returns the array with the matched property

controller.set('model', App.Fields.filterProperty('id',model.id));

也会做窍门

这篇关于EmberJS - 如何过滤数组并通过路由器将其传递给模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆