Backbone.js:将值传递给模型url

时间:2015-04-19 10:27:08

标签: javascript backbone.js

我的模特:

var UsersID = Backbone.Collection.extend({
    model:Wine,
    url:"api/wines/id"
});

我的观点:

var EditUser = Backbone.View.extend({
    el: '.page2',
    render: function (options) {
        //console.log(options.id);
        var wine = options.id;
        //console.log(wine);
        var that = this,
            users = new UsersID({ id:wine });

        users.fetch({
            success: function (users) {
                var template = _.template($('#user-details-template').html(), {users: users.models});
                that.$el.html(template);
            }
        })
    }
});

无法正常工作:型号网址未收到数据。

1 个答案:

答案 0 :(得分:0)

这是我的方式:

users.url = 'api/wines/' + id;
users.fetch({
            success: function (users) {
                var template = _.template($('#user-details-template').html(), {users: users.models});
                that.$el.html(template);
            }
        })