【发布时间】:2018-04-03 20:00:04
【问题描述】:
我正在使用 Angular 5 + Breeze JS + 微风-bridge2-angular。
假设我们有一个Company 实体,它具有多个Address 和Address 实体类型的导航属性,而它自己又具有一些导航属性,例如Country 等:
import { Entity } from "breeze-client"; // From https://www.npmjs.com/package/breeze-client package
export class Company implements Entity {
billingAddress: Address;
shippingAddress: Address;
}
export class Address implements Entity {
country1: Country;
country2: Country;
}
export class Country implements Entity {
...
}
所有实体都已查询到EntityMnager,无需从服务器查询任何内容。
如何实现一个方法(可能使用我目前缺少的一些 Breeze JS API) 采用父 Company 实体和一个带点属性路径的 string[] 并返回一个平面 @ 987654330@ 包含父实体和使用这些虚线路径定位的所有子实体的列表?
虚线路径与我们在 Breeze 查询中使用 expand() 方法相同(请参阅虚线展开路径 here),即:
const company: Company = ...; // Query Company and its children into EntityManager
const paths: string[] = [
"billingAddress",
"shippingAddress",
"billingAddress.country1",
"billingAddress.country2"];
getEntitiesFlat(entity: Entity, paths: string[]): Entity[] {
// Not sure how to implement getChildren() method below
const childEntities: Entity[] = this.getChildren(entity, paths);
return [entity].concat(childEntities);
}
顺便说一句,我正在尝试删除父实体及其特定子实体,以上是迄今为止我受到 DevForce 框架启发的最简洁的方法。我们非常欢迎更好的想法。
【问题讨论】:
标签: javascript angular typescript breeze devforce