使用requireJs Backbone.RelationalModel [英] Backbone.RelationalModel using requireJs
问题描述
我想用 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屋!