문제

I am using Backbone with a RESTful interface that is provided by a 3rd party (so I can not change it).

For one of the models (which is read only) the RESTful interface states that you use the HTTP OPTIONS verb not the GET verb. Can I tell backbone to use "OPTIONS" not "GET" just for that model as other models use GET

도움이 되었습니까?

해결책

You should be able to do something like this in your model definition:

sync: function(method, model, options){
  if(method !== "read") throw "Read-only model cannot be called with non-read method";

  options || (options = {});
  var params = {type: "OPTIONS", dataType: 'json'};

  if (!options.url) {
    params.url = _.result(model, 'url') || urlError();
  }

  var xhr = options.xhr = Backbone.ajax(_.extend(, options));
  model.trigger('request', model, xhr, options);
  return xhr;
}

In opther words, you need to rewrite the sync method for your model so it behaves like you want it to (i.e. sending OPTIONS verb). Take a look at Backbone's sync implementation for inspiration: http://backbonejs.org/docs/backbone.html#section-143

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top