【发布时间】:2012-12-20 14:29:56
【问题描述】:
如果我这样做了
var model = new Model({ id : 'someNewId'});
model.fecth();
然后我得到一个具有默认值的模型,因为服务器上不存在具有“someNewId”概念的模型。
确保模型确实存在于服务器上的最佳方法是什么?
【问题讨论】:
标签: backbone.js model
如果我这样做了
var model = new Model({ id : 'someNewId'});
model.fecth();
然后我得到一个具有默认值的模型,因为服务器上不存在具有“someNewId”概念的模型。
确保模型确实存在于服务器上的最佳方法是什么?
【问题讨论】:
标签: backbone.js model
这实际上取决于您的服务器配置。通常,RESTful 服务会返回 HTTP 错误代码 404 以指示未找到资源。
model.fetch({
success: function(model, response, options) {
//model exists and is now populated
},
error: function(model, xhr, options) {
if(xhr.status === 404) {
//model was not found
}
else {
//some other error
}
}
}
【讨论】: