2013-11-05 47 views
-1

我在我的模型上创建了一个名为'post'的函数,我想通过POST请求通过自定义url(下面的示例)向服务器发送请求。我如何设置url而不影响rootUrl发送请求? TIA!Backbone.JS:模型功能的自定义url

MyModel = Backbone.Model.extend({ 
    urlRoot: '../mymodel' 
    initialize: function(){ 

    }, 
    post: function(){ 
     // how put the url here? 
     // this is the custom url: '../post/mymodel/' + this.model.get('id') 
     // this is the expected log on server: 
     // POST: ../post/mymodel/323133 
}); 

回答

1

只需使用的url代替urlRoot

注意model.url委托给model.collection.url除另有规定

了解更多关于model.url

+0

谢谢!但我怎么能通过POST请求? – jrsalunga

0

您可以使用Ajax:

post: function(){ 
    $.post('../post/mymodel/' + this.model.get('id'), function(data) { 
     $(".result").html(data); 
    }); 
}