设想
我正在使用主干制作联系人管理器。我有一个表单,当用户输入数据并按下提交按钮时,用户的数据会进入服务器并将其保存在数据库中。
问题
在将其添加到数据库之前,它确实有效。但是,我也想在添加到数据库后更新集合。出于这个原因,我使用以下代码行来更新集合。
addContact: function (e) {
e.preventDefault();
this.collection.create({
first_name: this.$('#first_name').val(),
last_name: this.$('#last_name').val(),
email_address: this.$('#email_address').val(),
description: this.$('#description').val()
}, { wait: true });
console.log(this.collection);
}
上面的函数确实将数据添加到数据库,但它不更新集合。但是当我删除它时{wait: true}
,它会更新这个集合。
问题
为什么wait: true
不允许更新集合,我怎样才能使它工作wait: true
?
更新
我还添加了如下回调函数
{wait: true, success: this.successCallback}
并像这样添加了该功能
successCallback: function (collection) {
console.log('call back');
console.log(this.collection);
}
但它在控制台中没有显示此功能?
更新 2
错误函数截图
更新 3
xhr 截图