如何用Backbone-Relational表示UML关系?

时间:2012-02-10 09:37:48

标签: backbone.js backbone-relational

我的Class Diagram看起来像这样:

ModelA 1------* ModelB 1------* ModelC 1------* ModelD

修改:

数据看起来像那样

数据:

{   "Titel" : "ModelA",
    "ModelA" : [
        {
          "Titel" : "ModelB1",
          "ModelB1" : [
                              {
              "Titel" : "ModelC1",
                              "ModelC1":[
                                { "Titel" : "ModelD1"   },
                                { "Titel" : "ModelD2"   },
                                { "Titel" : "ModelD3"   }
                              },
                              {
              "Titel" : "ModelC2",
                              "ModelC2":[
                                { "Titel" : "ModelD21"   },
                                { "Titel" : "ModelD22"   },
                                { "Titel" : "ModelD23"   }
                              },
                              ]
                 },
                 {
          "Titel" : "ModelB2",
          "ModelB2" : [
                              {
              "Titel" : "ModelC1",
                              "ModelC1":[
                                { "Titel" : "ModelD1"   },
                                { "Titel" : "ModelD2"   },
                                { "Titel" : "ModelD3"   }
                              },
                              {
              "Titel" : "ModelC2",
                              "ModelC2":[
                                { "Titel" : "ModelD21"   },
                                { "Titel" : "ModelD22"   },
                                { "Titel" : "ModelD23"   }
                              },
                              ]
                 }]
 }

我创建了那些RelationalModel:

ModelA:

ModelA = Backbone.RelationalModel.extend({

  relations:[{
    type: Backbone.HasMany,
    key: 'modelb',
    relatedModel: 'ModelB',
    collectionType: 'ModelBCollection',
    reverseRelation:{
      key: 'belong To',
      includeInJSON: 'id'
    }
  }] });

ModelB:

ModelB = Backbone.RelationalModel.extend({

  relations:[{
    type: Backbone.HasMany,
    key: 'modelc',
    relatedModel: 'ModelC',
    collectionType: 'ModelCCollection',
    reverseRelation:{
      key: 'belong To',
      includeInJSON: 'id'
    }
  }] });

ModelC:

ModelC = Backbone.RelationalModel.extend({

  relations:[{
    type: Backbone.HasMany,
    key: 'modeld',
    relatedModel: 'ModelD',
    collectionType: 'ModelDCollection',
    reverseRelation:{
      key: 'belong To',
      includeInJSON: 'id'
    }
  }] });

ModelD:

ModelD = Backbone.Model.extend({ });

收藏:

 ModelACollection = Backbone.Collection.extend({ model: ModelA });
 ModelBCollection = Backbone.Collection.extend({ model: ModelB });
 ModelCCollection = Backbone.Collection.extend({ model: ModelC });
 ModelDCollection = Backbone.Collection.extend({ model: ModelD });

我在路由器中执行此操作:

路由器:

var obja = new ModelACollection(data);
var objb = new ModelBCollection(data.objb);
var objc = new ModelCCollection(data.objc);
var objd = new ModelDCollection(data.objd);

所有都被获取但有很多警告(firefox,chrome)看起来像这样:

警告:

Relation=%o; no model, key or relatedModel (%o, %o, %o) .... 
  1. 此警告的含义是什么?
  2. 用thebone-relational表示这种类关系的权利不是吗?
  3. 如果没有?

    我如何将其表示为Backbone ModelRelational?

1 个答案:

答案 0 :(得分:0)

在模型A中,您正在定义

key: 'modelb'

链接到模型B.但是,键应该是“一个字符串。在relatedModel上引用一个属性名称”(基于文档)。而且我看不到和模型字段叫做modelb