backbone.js modify specific fields of model after fetch the collection -


var items=[{"endsat": "2013-05-26t07:00:00z","id": 1,"name": "niuniu1"}, {"endsat": "2013-05-26t07:00:00z","id": 2,"name": "niuniu2"}]  itemmodel=backbone.model.extend({}); itemcollection=backbone.collection.extend({     model:itemmodel,     url: '...',      parse: function(response) {        return response.items;     }  }) 

if have series of data items, when build model, each model, it's endat "2013-05-26t07:00:00z". can modify model or data process "2013-05-26"?

i foreach loop inside collection process date, i'm wondering if there better pracitce parse inside model?

thanks!

the practice use 1 said you've thought - implementing custom parse on model. documentation states, called after sync. see here: http://backbonejs.org/#model-parse

itemmodel = backbone.model.extend({     parse: function(response,options) {        //perform work on 'response',         //    return attributes model should have.     }; }) 

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 -