如何对查询进行更复杂的排序,我目前有这样的查询:
var store = Ext.create('Rally.data.custom.Store',{
data: changes,
limit: 'Infinity',
pageSize: 5000,
sorters: [
{
property: 'ReleaseScope',
direction: 'ASC'
},
{
property: 'ScheduleState',
direction: 'DESC'
}
]
});
因为ScheduleState是水合的,我无法按正常数字排序,我可以使用某种匹配器定义顺序吗?
即。说我想按顺序显示[接受,完成,进行中,定义,积压] 而且,如果我想进一步复杂化并首先用故事点展示故事,比如
All stories with a story point value != 0
Sorted by schedulestate [accepted, completed, in-progress, defined etc..]
stories with no story point value
some other sort here possibly
答案 0 :(得分:2)
您可以传递sorterFn而不是属性/方向组合来实现自定义排序逻辑:
sorters: [
{
sorterFn: function(a, b) {
var scheduleStates = ['Accepted', 'Completed', 'In-Progress', 'Defined'],
aState = a.get('ScheduleState'),
aIndex = _.indexOf(scheduleStates, aState),
bState = b.get('ScheduleState'),
bIndex = _.indexOf(scheduleStates, bState);
return a - b;
}
}
]
上面的函数应该根据我认为的计划状态下降对它们进行排序。