在骨干网和服务器上,我在 id (api/order/ID/call 和 api/order/ID/status)之后提出了具有不同端点的请求。我显然需要根据不同的操作来设置这些。我通过扩展/覆盖模型同步获得了工作状态:
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);
}
});
},
我希望能够通过同步/保存/设置将不同的端点连接到 url