在Ember.js中,我嘗試綁定一個handlebars條件,該條件返回promise的一個ember-data fetch結果。如何將一個handlebars變量綁定到ember.js中的承諾
我知道承諾有成功回調,但我不明白如何將成功的結果綁定到計算屬性的值。計算屬性的值總是似乎是真的,因爲它返回承諾。
{{#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')
燼數據版本://最後承諾:ef11bff(2013年8月26日20時54分06秒-0700)
這個答案是有幫助的,但是因爲在這裏你有this.get(「players.length」)不能解決我的問題,它的作品,因爲你已經加載了燈具進入記憶。在我的情況下,這將返回一個承諾,我陷入了同樣的情況,我該如何等待承諾解決。 – Chandler