(fix) Respect order of cards list
This commit is contained in:
parent
ee0e45cad6
commit
8c8070ff16
|
@ -248,7 +248,7 @@
|
|||
* @param {object} [options] - additional options to the query
|
||||
* @returns a collection of Cards instances
|
||||
*/
|
||||
AddressBook.prototype.$filter = function(search, excludedCards, options) {
|
||||
AddressBook.prototype.$filter = function(search, options, excludedCards) {
|
||||
var _this = this,
|
||||
params = {
|
||||
search: 'name_or_address',
|
||||
|
@ -315,6 +315,17 @@
|
|||
cards.splice(index, 0, card);
|
||||
}
|
||||
});
|
||||
// Respect the order of the results
|
||||
_.each(results, function(data, index) {
|
||||
var oldIndex, removedCards;
|
||||
if (cards[index].id != data.id) {
|
||||
oldIndex = _.findIndex(cards, function(card) {
|
||||
return card.id == data.id;
|
||||
});
|
||||
removedCards = cards.splice(oldIndex, 1);
|
||||
cards.splice(index, 0, removedCards[0]);
|
||||
}
|
||||
});
|
||||
return cards;
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue