سؤال

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