How to fetch a Backbone.js model by something other than the ID?

前端 未结 5 1344
-上瘾入骨i
-上瘾入骨i 2021-02-15 14:48

Backbone.js\'s default, RESTful approach to fetching a model by the ID is easy and straight-forward. However, I can\'t seem to find any examples of fetching a model by a differe

5条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-15 15:19

    this is simple model.fetch is same as $.ajax in some way

    model = Backbone.Model.extend({
        urlRoot: "/root/"
    });
    
    var Model = new model();
    
    Model.fetch({
        beforeSend: function () {
            console.log("before");
        },
        data: {
            param1: "param1",
            param2: "param2"
        },
        success: function () {
            console.log("success");
        },
        error: function () {
            console.log("failure");
        }
    });
    

提交回复
热议问题