Breeze JS - 从 object 图扩展模型
Breeze JS - Extending model from object graph
目前我可以使用以下代码扩展我的产品实体的 breeze 模型实体类型:
function registerProduct(metadataStore) {
function Product(){}
// description property
Object.defineProperty(Product.prototype,'description', {
// TODO: handle selected globalization language
get: function () {
return this.descripFr;
}
})
metadataStore.registerEntityTypeCtor('Product',Product);
}
我遇到的问题是在扩展 属性 中使用实体图(在本例中为代码对齐)中的 属性,如下所示:
Object.defineProperty(Product.prototype,'name', {
get: function () {
var codeligne = this.codeligne;
var name = codeligne.ligne + '-' + this.codeprod;
return name;
}
})
这会引发 codeligne.ligne 的未定义异常。
如果我直接在 ng-repeat 中使用 codeligne.ligne,那么 属性 会正确显示,所以 Breeze 似乎知道它。
关于在扩展模型时如何使用 object 的代码联线有什么建议吗?
可能 "ligne" 导航 属性 表示的实体尚未加载。在引用其属性之前,您应该检查它是否包含一个值。
Object.defineProperty(Product.prototype, 'name', {
get: function () {
var codeligne = this.codeligne;
if (!codeligne) {
return null;
}
var name = codeligne.ligne + '-' + this.codeprod;
return name;
}
})
目前我可以使用以下代码扩展我的产品实体的 breeze 模型实体类型:
function registerProduct(metadataStore) {
function Product(){}
// description property
Object.defineProperty(Product.prototype,'description', {
// TODO: handle selected globalization language
get: function () {
return this.descripFr;
}
})
metadataStore.registerEntityTypeCtor('Product',Product);
}
我遇到的问题是在扩展 属性 中使用实体图(在本例中为代码对齐)中的 属性,如下所示:
Object.defineProperty(Product.prototype,'name', {
get: function () {
var codeligne = this.codeligne;
var name = codeligne.ligne + '-' + this.codeprod;
return name;
}
})
这会引发 codeligne.ligne 的未定义异常。 如果我直接在 ng-repeat 中使用 codeligne.ligne,那么 属性 会正确显示,所以 Breeze 似乎知道它。
关于在扩展模型时如何使用 object 的代码联线有什么建议吗?
可能 "ligne" 导航 属性 表示的实体尚未加载。在引用其属性之前,您应该检查它是否包含一个值。
Object.defineProperty(Product.prototype, 'name', {
get: function () {
var codeligne = this.codeligne;
if (!codeligne) {
return null;
}
var name = codeligne.ligne + '-' + this.codeprod;
return name;
}
})