문제

i'm having a problem with destroy method. I can save and see the HTTP activity in my firebug but when i use destroy method i can't see anything. Can anybody explain why ?

Backbone.emulateHTTP = true;
Backbone.emulateJSON = true;

var Hacker = Backbone.Model.extend({
      url:"http://localhost/backbone051/save.php",
});

var hacker = new Hacker();
hacker.set({name:"Herman Ganteng",age:"23"});
hacker.destroy(); //doesn't show any activity :(
도움이 되었습니까?

해결책

Your model has no Id field. Typically the Id would be populated by a previous fetch call. In this trivial example you could hard code one like this:

var Hacker = Backbone.Model.extend({
     id: "something",
     url:"http://localhost/backbone051/save.php",
});

This will result in a POST at the url specified.

다른 팁

You haven't saved it first so destroying it will not send any http request.

Similar to mfalto, to make it dynamic, you should include 'id' (for each model) as part of the data to be fetched by the collection from you php script. This will be considered the 'id' of each model in your collection then.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top