骨干:在添加到集合之前从服务器获取新模型
Backbone: grab new model from server before adding to collection
目前,当我创建一个模型时,它直接进入集合并保存到服务器,但是服务器添加了额外的信息模型,直到页面刷新时才会看到。我试图从服务器添加新模型到集合,而不是从使模型的表单。
这是我的添加方法add:function(tenant){
var values = _.extend(this.$el.find(':input').serializeJSON(), {active: true , modelType:"tenant"})
console.log(values)
var newView = tenants.create(values, {// FIX REPONCE
success:function(model,response){
console.log(response);
console.log(model.isNew());
},
error:function(model,response){
console.log(response.responseText);
}
},{wait: true},{silent: true})
}
当它到达model.IsNew()时,它返回true,这意味着它还没有到达服务器。我怎样才能退回服务器模型?
collection.create
的第二个参数是options
,但是您分别传递了选项{wait: true}
和{silent: true}
作为第三和第四个参数。这就是为什么它们不起作用。试试这个:
var newView = tenants.create(values, {
wait: true,
silent: true,
success:function(model,response){
console.log(response);
console.log(model.isNew());
},
error:function(model,response){
console.log(response.responseText);
}
});
相关文章:
- 如何从Angularjs中的新日期获取日期格式
- Sequelize associations:set[Models]添加新模型,而不是关联现有模型
- 使用 ng 模型获取数据时遇到问题
- 在获取后将新模型准备到集合中(不带比较器)
- 如何将数据从模型获取到JavaScriptMVC4
- 主干中的比较器在添加新模型时需要排序调用
- 如何在创建保存新模型时获取id
- Emberjs操作模型不会初始化新模型
- 如何在模型获取完所有信息后才将其传递给视图's数据
- 在 View.event Backbone.js 中创建新模型
- 挖空,映射后从视图模型获取 JSON
- 从视图中的模型获取属性的主干
- 主干.js:仅添加来自 JSON 集合获取的新模型
- Yii:使用 ajax 动态加载新模型
- 为什么当我将数据选项添加到骨干模型获取时,它不会触发回调
- 如何在角度.js中使用ng模型获取按钮文本
- 主干模型获取属性函数返回上次更新的值
- 将数据从模型获取到视图
- MVC 3使用下拉列表和ajax来获取新模型
- 骨干:在添加到集合之前从服务器获取新模型