【问题标题】:Ember computed property returns a filterEmber 计算属性返回一个过滤器
【发布时间】:2013-04-29 20:40:39
【问题描述】:

我的控制器上有一个简单的属性。它用于呈现对话中所有电子邮件的列表。

conversation: (->
  App.Email.filter (otherEmail) => 
    @get('model').isIncludedInConversation otherEmail
).property('model')

当我转到该页面时,一切正常且花花公子,因为尚未计算 CP。当我发送新电子邮件时,conversation 属性未更新。我需要切换我正在查看的电子邮件以触发 conversation 重新计算。

我知道过滤器正在更新。问题是 CP 的值没有改变,底层的{{#each conversation}} 没有更新。我怎样才能做到这一点?

编辑:我在这里添加了小提琴:http://jsfiddle.net/twinturbo/GUeE3/1/

【问题讨论】:

标签: ember.js ember-data


【解决方案1】:

我不熟悉coffeescript,所以我假设你的代码相当于:

conversation: function() {
  var self = this;
  App.Email.filter( function( otherEmail ) {
    return self.get('model').isIncludedInConversation( otherEmail );
  }); 
)}.property('model')

我想说你应该在过滤函数之外捕获model

conversation: (->
  _model = @get('model')
  App.Email.filter (otherEmail) => 
    _model.isIncludedInConversation otherEmail
).property('model')

此代码适用于我最新版本的 ember 和 ember 数据。

【讨论】:

    猜你喜欢
    • 2014-06-18
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多