how to use Backbone.js, but in the NO-RESTful way?

前端 未结 3 1724
野趣味
野趣味 2021-02-01 07:02

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

3条回答
  •  不知归路
    2021-02-01 07:50

    The best option in your case is plugin like Backbone.service. It is Backbone service for non restful or semi restful apis.

    // define server targets / endpoints
    var targets = {
      login: ["/login", "post"],
      signup: ["/signup", "post"],
      logout: ["/logout", "get"],
      search: "/search" // defaults to get
      resetPassword: ["/resetpassword", "post"],
      updateSettings: ["/updateSettings", "post"]
    };
    
    // standalone service
    var service = new Backbone.Service({ url: "http://localhost:5000", targets: targets });
    
    // extend backbone model
    var User = Backbone.Model.extend(service);
    

    You can use it like this:

    var user = new User();
    user.login({ username: 'bob', password: 'secret' });
    

提交回复
热议问题