在骨干网中,在服务器上,我在id(api / order / ID / call和api / order / ID / status)之后放置了不同端点的请求。我需要根据不同的动作明确设置这些。我通过扩展/覆盖模型sync来获得状态:
sync: function(method, model, options){
if (method == 'PUT' || method == 'update') {
model.url = '/venues/orders/' + model.id + '/status';
var jsonData = {};
jsonData.staffid = 1;
jsonData.groupid = 0;
jsonData.statusid = this.get('status.statusid');
//if the options url is set use that otherwise use /status
if( options.url ){
model.url = options.url;
}
options.data = JSON.stringify(jsonData);
}
return Backbone.sync(method, model, options);
}
我有一个调用函数,它设置了选项url:
CallToBar: function(el){
log("CallToBar Action");
el.preventDefault();
el.stopPropagation();
var target = $(el.currentTarget);
target.text('Calling...');
var that = this;
this.model.save({}, {
url: '/venues/orders/' + this.model.id + '/call',
data: '',
success: function(){
target.text('Called');
timeout = setTimeout(function() {
if( !$(this.el).find('.additional-options').hasClass('hide') ){
that.orderClicked();
}
target.text('Call to bar');
}, 1500);
}
});
},
我希望能够使用sync / save / set
将不同的端点连接到网址答案 0 :(得分:0)