1

要在 Backbone 集合中设置数据:

var someList = ['a', 'b', 'c'];
collection.reset({models:someList});

有没有办法用 a 来做到这一点model而不必调用set()每一个属性?

例子

var pop_star = {
    first_name: "Stacey",
    last_name:  "Ferguson"
}
// There is no "reset()" function on a model, but is there something like it?
model.reset(pop_star);   

谢谢!

4

1 回答 1

4

实际上是您正在寻找的Model.set() 。它可以接收 ahash并且只会将属性更新到散列中。

model.set(pop_star);
于 2012-07-22T19:24:38.847 回答