javascript - Adding an array of collections to the Previously added collection in Backbone JS -


hi new backbone js , playing around , trying learn. stuck quite time now. appreciated, in advance!

this model

var human = backbone.model.extend({   defaults: {     name: 'fetus',     age: 0,     child:'noname'   },  });     var human = new human();  human.set({ name: "thomas", age: 67, child: "ryan"}); //works fine 

this collection

var person = backbone.collection.extend({   model: human });   var human1 = new human({ name: "khaleesi", age: "37", child: "drogon" }); var human2 = new human({ name: "rahul", age: "25", child: "rita" }); var human3 = new human({ name: "seema", age: "26", child: "maruti" });  var thepeople = new person([ human1, human2, human3]); document.write("</br>"); document.write(json.stringify( thepeople.models )); // works fine 

i want add these data previous array

var sm = this.person.add(new human([   { name: "hemath", age: "32", child: "sophie" },   { name: "siddharth", age: "26", child: "tom" } ]));  document.write(json.stringify( sm.models )); 

cant add next 2 array of data collection

you should add array collection

var sm = this.person.add([   { name: "hemath", age: "32", child: "sophie" },   { name: "siddharth", age: "26", child: "tom" } ]); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -