将对象设置为Backbone.js模型,而不必调用“;set()"在每一处房产上

Set an object to a Backbone.js model without having to call "set()" on every property

本文关键字:quot 一处 对象 设置 模型 js Backbone 不必 set 调用      更新时间:2023-12-23

要在主干集合中设置数据:

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

谢谢!

实际上就是您想要的Model.set()。它可以接收hash,并且只将属性更新到散列中。

model.set(pop_star);