Backbone收集网址可以依赖于型号urlRoot吗?

时间:2015-09-16 12:45:32

标签: javascript backbone.js

Backbone收集网址可以依赖于模型urlRoot吗?例如

var _User = Backbone.Model.extend({
    urlRoot: '/api/users',
    defaults: {
        email: ''
    }
});

var _Users = Backbone.Collection.extend({
    url: function() {
        return this.model.urlRoot;
    },
    model: _User
});

1 个答案:

答案 0 :(得分:1)

看起来像你想要的

var _User = Backbone.Model.extend({
    urlRoot: '/api/users',
    defaults: {
        email: ''
    }
});

var _Users = Backbone.Collection.extend({
    url: function url() {
      return this.model.prototype.urlRoot;
    },
    model: _User
});