如何用主干关系表示UML关系



我有这样的类图:

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"   }
                              },
                              ]
                 }]
 }

我创建了那些相关模型:

型号A:

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

型号B:

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

型号C:

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

型号D:

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. 这就是用主干关系表示这个类关系的权利,不是吗

如果没有?

如何将其表示为Backbone ModelRelational?

在模型A中,您正在定义

key: 'modelb'

链接到模型B。但是,键应该是"字符串。引用relatedModel上的属性名称"(基于文档)。我看不到名为modelb 的模型字段

相关内容

  • 没有找到相关文章