将collection的数组添加到Backbone JS中先前添加的collection

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

嗨,我是 Backbone JS 的新手,只是在玩弄和尝试学习。我已经坚持了很长一段时间了。任何帮助将不胜感激,提前致谢!

这是我的模特

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

这是我的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 )); // This also works fine

我想将这些数据添加到我之前的数组中

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 ));

无法真正将接下来的 2 个数据数组添加到我的 collection

你应该add数组到集合

var sm = this.Person.add([
  { name: "Hemath", age: "32", child: "sophie" },
  { name: "Siddharth", age: "26", child: "Tom" }
]);