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

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -