Backbone.JS:用于模型功能的自定义URL

时间:2013-11-05 03:39:38

标签: javascript backbone.js

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

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 
});

2 个答案:

答案 0 :(得分:1)

只需使用url代替urlRoot

请注意model.url委托给model.collection.url,除非另有说明

详细了解model.url

答案 1 :(得分:0)

您可以使用Ajax:

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