Breeze 按名称获取实体属性值-在客户端上
假设我有一个实体Person和一个字符串,它定义了属性的“路径”——比如“Address.Country”。是否有一个函数可以让我访问可观察的持有国?您可以从getProperty和setProperty方法开始Breeze 按名称获取实体属性值-在客户端上,breeze,Breeze,假设我有一个实体Person和一个字符串,它定义了属性的“路径”——比如“Address.Country”。是否有一个函数可以让我访问可观察的持有国?您可以从getProperty和setProperty方法开始 var address = myEntity.getProperty("Address"); var country = address.getProperty("Country"); 那你可以用 function getPropertyPathValue(obj, property
var address = myEntity.getProperty("Address");
var country = address.getProperty("Country");
那你可以用
function getPropertyPathValue(obj, propertyPath) {
var properties;
if (Array.isArray(propertyPath)) {
properties = propertyPath;
} else {
properties = propertyPath.split(".");
}
if (properties.length === 1) {
return obj.getProperty(propertyPath);
} else {
var nextValue = obj;
for (var i = 0; i < properties.length; i++) {
nextValue = nextValue.getProperty(properties[i]);
// == in next line is deliberate - checks for undefined or null.
if (nextValue == null) {
break;
}
}
return nextValue;
}
}
或
你试过什么?什么不起作用?你读过关于提问的帮助吗?我试图在breeze的文档和Api中找到这样的函数,但运气不好。看起来没有这样的功能可用,但很可能breeze在内部执行类似的操作。我可以写一个函数来做我想做的事情,但是如果它可用的话,我更愿意使用它。
var country = getPropertyPath(myEntity, "Address.Country");
var country = getPropertyPath(myEntity, ["Address", "Country"]);