(fix) Respect order of cards list

This commit is contained in:
Francis Lachapelle 2015-07-16 16:26:09 -04:00
parent ee0e45cad6
commit 8c8070ff16

View file

@ -248,7 +248,7 @@
* @param {object} [options] - additional options to the query * @param {object} [options] - additional options to the query
* @returns a collection of Cards instances * @returns a collection of Cards instances
*/ */
AddressBook.prototype.$filter = function(search, excludedCards, options) { AddressBook.prototype.$filter = function(search, options, excludedCards) {
var _this = this, var _this = this,
params = { params = {
search: 'name_or_address', search: 'name_or_address',
@ -315,6 +315,17 @@
cards.splice(index, 0, card); 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; return cards;
}); });
}; };