Backbone.RelationalModel using requireJs

妖精的绣舞 提交于 2019-12-08 11:52:07

问题


I would like to use RelationalModel using requireJs.

Here my code(*)

When I run my module, I get the following warning message:

Relation=d; 
no model, key or relatedModel (function (){a.apply(this,arguments)}, 
"tasks", 
undefined).

My questions are:

1) what does the warning message means?
2) relatedModel and collectionType are well defined in my relations or should I export the model and the collection in define call?


(*)

define([
    'backbone',
    'relationalModel'
], function (Backbone) {
    "use strict";

    var User = Backbone.RelationalModel.extend({

        relations: [{
            type: Backbone.HasMany,
            key: 'tasks',
            relatedModel: 'Task',
            collectionType: 'TaskCollection',
            reverseRelation: {
                key: 'hasUser',
                includeInJSON: 'id'
                // 'relatedModel' is automatically set to 'User'; the 'relationType' to 'HasOne'.
            }
        }]

    });

    return User;
});

回答1:


Look at this question: Creating nested models with backboneJS + backbone-relational + requireJS

By the way, exports.ModuleModel = ModuleModel; doesn't work for me. Instead, I use window.ModuleModel = ModuleModel. Yes, it's a bit ugly, but it works.



来源:https://stackoverflow.com/questions/11224858/backbone-relationalmodel-using-requirejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!