Backbone Relational - Uncaught TypeError:undefined不是函数

时间:2014-09-02 15:02:21

标签: javascript backbone.js undefined marionette backbone-relational

我在文件中定义了BackboneRelational模型:

define(function (require) {
var Backbone = require('backbone'),
    BackboneRelational = require('backbone.relational'),
    StudentDetails = require('./StudentDetails');

var Classroom = Backbone.RelationalModel.extend({
    url : "../server/student-records.json",
    relations : [{
        type: Backbone.HasMany,
        key: 'studentDetails',
        relatedModel: StudentDetails,
        collectionType: Backbone.Collection,
        fetchRelated: false
    }]
});

return Classroom;
});

我在另一个文件中使用此模型:

define(function(require) {
    var Marionette = require('marionette'),
        Classroom = require('../model/Classroom');

    var ClassroomController = Marionette.Controller.extend({
        initialize: function(args){
            this.mainRegion = args;

            var jsondata = new Classroom();

            jsondata.fetch({
                success:function(){
                    console.log(jsondata);
                    ......................
                    ....some code here....
                    ......................
                }
            });
        }
    });
    return ClassroomController;
});

我开始未捕获TypeError:未定义不是函数错误行:

var jsondata = new Classroom();

有人可以指出我哪里出错吗?

1 个答案:

答案 0 :(得分:2)

这可能是因为您没有为RelationalModel中为关系中使用的每个模型指定扩展名。一旦模型被用于关系,你实际上必须通过RelationalModel扩展它。希望有所帮助