使用requireJs Backbone.RelationalModel [英] Backbone.RelationalModel using requireJs

查看:156
本文介绍了使用requireJs Backbone.RelationalModel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 RelationalModel 使用 requireJs

下面我code(*)

当我跑我的模块,我得到以下警告消息:

 关联= D;
没有模型,钥匙或relatedModel(函数(){a.apply(这一点,参数)},
任务,
未定义)。

我的问题是:

1)什么是警告信息意味着什么?结果
2) relatedModel collectionType 在我的关系明确定义或者我应该导出模式定义打电话?


(*)

 定义([
    '骨干',
    relationalModel
],功能(骨干){
    使用严格的;    VAR用户= Backbone.RelationalModel.extend({        关系:[{
            类型:Backbone.HasMany,
            关键:'任务',
            relatedModel:'任务',
            collectionType:TaskCollection',
            reverseRelation:{
                键:hasUser',
                includeInJSON:ID
                //'relatedModel自动设置为用户;在relationType到HasOne。
            }
        }]    });    返回用户;
});


解决方案

看这个问题:<一href=\"http://stackoverflow.com/questions/9962695/creating-nested-models-with-backbonejs-backbone-relational-requirejs\">Creating嵌套模型与backboneJS +骨干关系+ requireJS

顺便说一句, exports.ModuleModel = ModuleModel; 不为我工作。相反,我使用 window.ModuleModel = ModuleModel 。是的,这是一个有点难看,但它工作。

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;
});

解决方案

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.

这篇关于使用requireJs Backbone.RelationalModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆