2013-11-05 46 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); 
    }); 
}