我可以帮助您进行翻译,请看下面的内容:
在视图代码中,稍后我将在点击事件上保存(使用
我在用户设置个人资料表单中使用了Backbone。我获取模型并将其信息呈现到表单中。当我保存模型时,所有参数都会被发送,而不仅仅是用户更改过的参数。
首先,我获取模型并在视图上呈现它:
// Fetch model and render on view
user = new User({ id: 123 });
user.fetch().done(function () {
view.render();
});
当用户更改字段时,我使用“set()”方法更新了模型:
"change .email": function () {
this.model.set("email", this.email.val());
}
在视图代码中,稍后我将在点击事件上保存(使用
patch:true
):"click .save": function () {
console.log(this.model.changedAttributes()); // Shows all the model attributes
this.model.save({ patch: true }); // Sends all the model attributes
}
我该如何避免在使用fetch
初始化模型后,Backbone将其标记为更改的状态?