我有一個模型值,當我做每個迭代它工作正常。如何在計算中對`desc`中的數組值進行排序?
<ul>
<li>See here : </li>
{{#each selectedCreditCard.balances.tenures as |balance|}}
<li>Balances is : {{balance}}</li>
{{/each}}
</ul>
但我要求按desc
的方式對值進行排序。所以我使用computed
方法來做desc
這個數組。
sortTenuresBy:['desc'],
sortedTenures: Ember.computed.sort('selectedCreditCard.balances.tenures', 'sortTenuresBy'),
maxTenure:Ember.computed(function(){
return this.get('sortedTenures').get('firstObject');
但得到錯誤的是這樣的:
Assertion Failed: When using @each to observe the array 3,8,12,24, the array must return an object
如何解決這一問題?請幫我
主要問題是我沒有價值的關鍵。它只是一個原始數組,如[1,2,3,4] – 3gwebtrain
如果你想獲得'max',你可以使用[Ember.computed.max](https://www.emberjs.com/api/ember/ 2.15 /命名空間/ Ember.computed /方法/最大?錨=最大值) – ykaragol