javascript - function: why are all children updating in this backbone collection? -


i have backbone collectionview holds x amount of companies. have collection of x amount of products.

i want random product , add list of "assets" on random company. (the company returned this.getrandomcompany() function)

but when run following function companies children updated same products @ once.

the result of console.log(randomcompany) single child, why children updating?

   addproduct: function() {         var randomproductindex = math.round(math.random() * (this.products.length));         var randomproduct = new app.companymodule.product({             "name": this.products[randomproductindex]         });          this.getrandomcompany(_.bind(function(randomcompany) {             console.log(randomcompany);             randomcompany.model.get("assets").add(randomproduct);             this.render();         }, this));     }, 

how company model defining assets property? if it's defined direct property of model or in defaults object, you'll behavior you're describing. if that's case, move defaults method, e.g.

var company = backbone.model.extend({     ...     defaults: function() {         return {             assets: []         }     },     ... }); 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -