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

前端 未结 3 1790
野趣味
野趣味 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:56

    Here's an example of a modified Backbone.js ajax call:

    var Forecast = Backbone.Model.extend({
      url: function() {
        return "http://api.wunderground.com/api/7eaec3b21b154448/conditions/q/" + this.get( "zip" ) + ".json";
      },
      parse : function( data, xhr ) {
        var observation = data.current_observation;
        return {
          id: observation.display_location.zip,
          url: observation.icon_url,
          state: observation.display_location.state_name,
          zip: observation.display_location.zip,
          city: observation.display_location.city,
          temperature: observation.temp_f
        };
      }
    });
    

    From: Elijah Manor's Intro to Backbone.JS

提交回复
热议问题