breeze获取实体的集合而不是对象

时间:2016-05-16 18:13:44

标签: javascript node.js breeze

使用restful node.js 服务器并发送包含在一个实体对象(Lookups)中的实体集合,一切正常,但集合中的实体被视为普通对象,而不是微风即可。有没有办法解决这个问题,而不是使用查找的实体是否可以使用复杂的对象,因为它只是作为持有者使用,仅此而已。谢谢你的帮助

服务器的响应采用这种格式

[
  oranges:[{id:1, name:'juicy'}, {id:2, name:'no seeds'}],
  apples:[{id:1, name:'red'}, {id:2, name:'green'}]
]

使用此查询:

breeze.EntityQuery.from('users/lookups')
            .using(this.manager).execute()
            .then(this.querySucceeded)
            .catch(this.queryFailed);

以下是查找的元数据代码

var entityType = {
   name: this.entityNames.Lookup,
   defaultResourceName: 'users/lookups',
   autoGeneratedKeyType: breeze.AutoGeneratedKeyType.Identity,
   dataProperties: {
      lookupID: {dataType: DT.Int32, isPartOfKey: true}
   },
   navigationProperties:  {
      apples: {
             entityTypeName: this.entityNames.Apple
       },
      orange: {
             entityTypeName: this.entityNames.Orange
       }
   }
};

Orange和Apple的元数据

var entityType = {
    name: this.entityNames.Apple,
    defaultResourceName: 'users/lookups/Apples',
    dataProperties: {
         id: {type: DT.Int32},
         image: {type: DT.String},
         name: { complexTypeName: 'Translation:#model', isNullable: false}
    }
 };


var entityType = {
    name: this.entityNames.Orange,
    defaultResourceName: 'users/lookups/Oranges',
    dataProperties: {
         id: {type: DT.Int32},
         image: {type: DT.String},
         name: { complexTypeName: 'Translation:#model', isNullable: false}
    }
 };

复杂类型翻译的元

var entityType = {
    name: 'Translation',
    isComplexType: true,
    dataProperties: {
         fr: {type: DT.String},
         en: {type: DT.String}
    }
 };

1 个答案:

答案 0 :(得分:1)

您对苹果和橙子的服务器响应应该具有响应数据中标识的类型。这样他们就可以被认为是他们的实体:

[
  oranges:[
    {$type:model.Orange, id:1, name:'juicy'}, 
    {$type:model.Orange, id:2, name:'no seeds'}
  ],
  apples:[
    {$type:model.Apple, id:1, name:'red'}, 
    {$type:model.Apple, id:2, name:'green'}
  ]
]

您可以查看有关lookups in the Breeze documentation

的更多信息
相关问题