backbone.js - underscore sortBy function on a backbone collection unable to identify the objects of the collection -
i have backbone collection sorted. using undescore.js function sortby. below code snippet
sortedcollection = collectiontosort.sortby(function(obj){ return obj.cost; })
but throws me error obj undefined. working when write code below:
sortedcollection = collectiontosort.sortby(function(obj){
obj = json.parse(json.stringify(obj));
return obj.cost; });
my question why couldn't identify obj
object inside sortby
function though json object unless reconvert json object
a backbone model passed sortby function, not object initialized model with.
sortedcollection = collectiontosort.sortby(function(model){ return model.get('cost') })
Comments
Post a Comment