如何在ember.js中使用FilterBy来处理多个数据

时间:2017-01-19 12:35:04

标签: ember.js

这是控制器chat.js代码

 queryParams: ['offer_id'],
 offer_id: null,
 filteredChat: Ember.computed('model.@each.offer_id','offer_id',
   function() {
    return this.get('model').filterBy("offer_id" ,this.get("offer_id")).filterBy("id", this.get("offer_id"))
  }),

我正在使用offer_id过滤聊天。

我想知道我可以使用filterBy这样两次 那是我的路线chat.js代码

queryParams:{
  offer_id:{
   refreshModel : true
 }     
},
model(params) {
      return this.store.query("chat", params).then(() => {
       let model = this.store.peekAll("chat")
       return model
  })
 },

我的模特chat.js

message: attr('string'),
offer_id: attr('string'),
stamp: attr('string'),
type: attr('string'),

1 个答案:

答案 0 :(得分:0)

你可以这样做,但要小心,你的依赖字符串是错误的。您还应该包含canvas

另外,您需要了解这会产生一个数组,其中包含model.@each.id offer_id的项目与id完全相同的项目你过滤了。这将导致offer_id offer_id等同于您过滤id的项目。

如果你想要版本,你可以这样做:

offer_id

所以你看,如果这项工作完全取决于你的期望。