admin管理员组文章数量:1317906
I have a very basic backbone (sample) application which just creates and destroys model items. When the model is created the object is persisted with a POST to the web server, but when the model is destroyed there is no DELETE sent to the server? Any idea why this might be?
very basic model:
window.User = Backbone.Model.extend({
urlRoot: 'users'
});
my test code just to create and delete the model:
var model = null;
$(".add").click(function(){
if (model == null) {
model = new window.User;
model.set({name: 'meeee'});
model.save();
}
});
$(".remove").click(function(){
if (model != null) {
model.destroy();
}
});
The JSON response when creating the model seems good too:
I have a very basic backbone (sample) application which just creates and destroys model items. When the model is created the object is persisted with a POST to the web server, but when the model is destroyed there is no DELETE sent to the server? Any idea why this might be?
very basic model:
window.User = Backbone.Model.extend({
urlRoot: 'users'
});
my test code just to create and delete the model:
var model = null;
$(".add").click(function(){
if (model == null) {
model = new window.User;
model.set({name: 'meeee'});
model.save();
}
});
$(".remove").click(function(){
if (model != null) {
model.destroy();
}
});
The JSON response when creating the model seems good too:
Share Improve this question edited Jun 3, 2012 at 22:26 Nippysaurus asked Jun 3, 2012 at 21:50 NippysaurusNippysaurus 20.4k21 gold badges80 silver badges130 bronze badges 2-
3
how does your server respond to the
save
request? If the model doesn't have an.id
attribute (Which the server is supposed to return when saving), it won't send any request. – Esailija Commented Jun 3, 2012 at 21:53 - updated the question with screenshot of json response. – Nippysaurus Commented Jun 3, 2012 at 22:27
1 Answer
Reset to default 12Backbone doesn't know that _id is the name you are using for your id field, unless you've modified your copy of Backbone.js somehow (please don't). To tell Backbone what the name of your id field is for some particular model, idAttribute in your Model definition. Otherwise, it defaults to the regular id
.
Without the "identity" field set, Backbone is going to consider that the the model instance "isNew" (a model instance which hasn't been persisted to the server), so when there's no "identity" (as in your case, as it doesn't know that your identity is, instead, _id
) there wouldn't be any need to destroy it on the server.
本文标签: javascriptwhy does backbone not send the deleteStack Overflow
版权声明:本文标题:javascript - why does backbone not send the delete? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742031602a2416543.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论