javascript - BackBoneJs donot Delete/Update Model to the server -
I have an application that makes reading / making / updating models and saving it to server but currently I I can read and save models from more databases. But I'm unable to delete / update servers and servers. Ideas are currently removed from the model, but the model itself is not here JSFiddle path Model Code> var model dialog = backbone.modeell extension ({default: function () {return {id: 0, name: "", address: ""}}}, / / if I add this idAttribute = "Id" It removes the value from the server / but I am unable to create a new model / new entry to the database: function () {// deletes the model but there are no changes or The server has a right-to-use contact with the var contactCollection ();}}};
Archive
Extension ({Model: modelContact, url: 'API / Contacts'}); var contact = new contactCollection;
ModelView
<.> var contactView = backbone.exe extension ({tagname: "tr", events: {// run fine "click on a.destroy": "clear"}, template: _.template ($ ("# NewContacttemplate") .HTML ()), // run fine start: function () {this.model ("change", this.render, this); This.model.on ('deleted', remove it, remove it); }, Render: function () {// run fine. $ El.html (this.template (this.model.toJSON ())); This return; }, Clear: function () {this.model.clear (); }}); Main view Events: {// run OK "# btnsave", click on "CreateNewContact"}, initialize: function () {// it's okay .name = input = $. ("# Contactname"); this.adressing input = $ ("Contact.on (" add ", this.AddContact, this); contact.on (" reset ", this .ad contacts, this); contacts.fetch (); // Note: populate all database values }}, AddContact: function (contact) {// run fineVirview = new contact view ({model: contact}); $ ("# tblcontact tbody"). Append (view.re Nder (). El);}, AddContacts: Function () {// fine contacts.each (this.AddContact);}, CreateNewContact: function (e) {// run fine contacts .create ({name: this. Nameinput.val (), address: this .addressinput.val ()});}}); var m = new main;
});
You now have url
defined on your backbone.cololution
but your Backbone.model
, which means that you have to do all AJAX work through archive
. It does not have to be that way: you can add a second URL to your server-side for the operation of AJAX, or both can share a URL (if you can do it properly )
Important part, if you select Once you have this call this.destroy (); If you want to be able to call and display it on your server, then you need it:
url
property on your backbone.model
that is set to that server-side URL this.destroy ();
A deleted AJAX request, your server will receive that request and be aware that it should remove the appropriate database records, and then the model will be removed on both client- and server-side.
Comments
Post a Comment