I'm now a front-end developer, and I have a project which is fine to use BackboneJS, and the server-side is written by others. Is there anyone who can tell me how to override delete, update, add, and so on in a not-RESTful way? The server-side's URL may be like this:
www.domain.com/addBookById
www.domain.com/removeBookById
Thanks a lot!!
The developers should make use of Backbone JS while developing a single-page Java application. Backbone JS features Model View Framework, which allows much more than structuring JavaScript architecture. It will help the developers eliminate several issues that they might be facing while developing apps.
BackboneJS is a lightweight JavaScript library that allows to develop and structure the client side applications that run in a web browser. It offers MVC framework which abstracts data into models, DOM into views and bind these two using events.
Backbone. js is a JavaScript framework that helps you organize your code. It is literally a backbone upon which you build your application.
You can use the Backbone. Model without jQuery, but Backbone.
Backbone uses Backbone.sync
to manage all communication with the server. There are two important things about sync
for you; first of all, it looks like this:
The method signature of Backbone.sync is
sync(method, model, [options])
- method – the CRUD method (
"create"
,"read"
,"update"
, or"delete"
)- model – the model to be saved (or collection to be read)
- options – success and error callbacks, and all other jQuery request options
and the second is that you can override sync
on a per-model and per-collection basis. So you can add your own sync
implementation to your model:
var M = Backbone.Model.extend({
sync: function(method, model, options) {
//...
},
//...
});
If you look at method
you can decide which URL to use and whether you're doing a GET, POST, ... request. The model
will tell you what data to send to the server. You'll want to merge options
into the $.ajax
options you want to use. Have a look at the standard implementation of Backbone.sync
, it is pretty straight forward and should show you what you need to do: just replace the URL handling and drop some of the features you don't care about (such as emulateHTTP
and emulateJSON
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With