将对象设置为Backbone.js模型,而不必在每个属性上调用“set()”

时间:2012-07-22 19:12:48

标签: javascript backbone.js

在Backbone集合中设置数据:

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

有没有办法使用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);   

谢谢!

1 个答案:

答案 0 :(得分:4)

实际上是您正在寻找的Model.set()。它可以接收hash,它只会将属性更新为哈希值。

model.set(pop_star);