gpt4 book ai didi

javascript - Breeze 获取实体而不是对象的集合

转载 作者:行者123 更新时间:2023-12-03 06:56:15 27 4
gpt4 key购买 nike

使用安静的node.js服务器并发送包装在一个实体对象(查找)中的一组实体,一切正常,但集合中的实体被视为普通对象,而不是<强> Breeze 。有没有办法解决这个问题,除了使用实体进行查找之外,还可以使用复杂的对象,因为它仅用作持有者,仅此而已。感谢您的帮助

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

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

最佳答案

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

[
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的信息

关于javascript - Breeze 获取实体而不是对象的集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37260503/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com