javascript - Taking in data from a function using _.clone(this.model.attributes) -


my issue have view , utils function trying connect model data.

in view; have function:

getcalculateddata: function() {     var calculateddata = utils.calculateamounts(_.clone(this.model.attributes)) }, 

this retrieves model data key/value object. in utils function want retrieve data can use calculations. want make function this:

calculatedamounts: function() {     //retrieve data }, 

how retrieve values. lets firstname, lastname, , state in model retrieving in view. create variable hash holds them this:

calculatedamounts: function() {     firstname : this.model.get('firstname');     //etc }, 

how retrieve values out of object?

thanks

i not sure understand question, in calculatedamounts method, why don't use variable passed when called method in getcalculateddata?

your code this:

getcalculateddata: function() {   var calculateddata = utils.calculateamounts(this.model) },  calculatedamounts: function(mymodel) {   firstname : mymodel.get('firstname');   //etc }, 

also, if going modify model in calculatedamounts , not want modifications mirror outside calculatedamounts scope, should deep copy model object.
1 common way use extend() method of jquery. like:

calculatedamounts: function(mymodel) {   var deepcopiedmodel = $.extend(true, {}, mymodel);   firstname : deepcopiedmodel.get('firstname');   //etc }, 


edit:
also, avoid passing this.model.attributes calculatedamounts() method if want use get() method in it.
this.model.attributes object object, , not backbone.model object.

the .get() call if pass this.model.attributes param method part of object's prototype, , not method part of backbone.model's prototype.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -