在 Ember.js 中,我试图以返回承诺的 ember-data 获取结果为条件绑定把手。
我知道承诺有一个成功的回调,但我不明白如何将成功的结果绑定到计算属性的值。计算属性的值似乎总是为真,因为它返回了承诺。
{{#if game.moreThanOnePlayer}}
<span> it was true </span>
{{/if}}
App.Game = DS.Model.extend
players: DS.hasMany 'App.Player'
moreThanOnePlayer: (->
promise = @get('players') #triggers ajax call that returns a promise
promise.then(
(players) -> #promise success call back
return players.length > 1 #this is what I want the computed property value to be
)
#but the return value of the function is still a promise, which always evaluates to true.
return promise
).property('players')
ember-data version: // 上次提交:ef11bff (2013-08-26 20:54:06 -0700)