按属性按优先排序 [英] Sorting by properties by priority
问题描述
获胜
,出价
,关闭
和观看
这些属性是真的还是假的
我想对项目进行排序,以便所有的获胜项目都是第一个,然后是所有的投标项目,然后是所有的观看项目,然后所有关闭的项目。
我该如何实现?我需要在一个排序函数中执行所有操作,还是可以指定多个函数进行排序?
我已经尝试过获胜了,但我不确定从这里去哪里
sortedItems:Ember.computed.sort('filteredItems',function(a,b){
if(a.get('winner')== true&& a.get('winner')!= b.get('winner')){
return -1;
}
if(a.get('winner')== b.get('winner')){
return 0;
}
if(a.get 'win')== false&& a.get('winner')!= b.get('winner')){
return 1;
}
}),
我建议使用这样的排序功能。
函数(a,b){
var status = {获胜:1 ,招标:2,关闭:3,看:4};
return status [a.bidStatus] - status [b.bidStatus];
}
I have items that I'm wanting to sort, my items have computed properties on the model that include winning
, bidding
, closed
, and watching
each of these properties is true or false
I want to sort the items so that all the winning items are first, then all the bidding items, then all the watching items, then all the closed items.
How might I achieve this? Do I need to do it all in one sort function or can I specify multiple functions to sort by?
I've tried this for winning, but I'm not sure where to go from here
sortedItems: Ember.computed.sort('filteredItems',function(a,b){
if(a.get('winning') == true && a.get('winning') != b.get('winning')){
return -1;
}
if(a.get('winning') == b.get('winning')){
return 0;
}
if(a.get('winning') == false && a.get('winning') != b.get('winning')){
return 1;
}
}),
I suggest to use a sorting function like this. It sorts by grouping the bid status.
function (a, b) {
var status = { winning: 1, bidding: 2, closed: 3, watching: 4 };
return status[a.bidStatus] - status[b.bidStatus];
}
这篇关于按属性按优先排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!