我发现了一个关于 ComplexType 属性的错误。我有一个对象,它有一个属性,它是我在客户端元数据中定义为复杂属性的其他对象的集合,即“isComplexType:true”。但是,复杂类型的所有属性都设置为“未定义”。我做了一些调试,发现了这个:
// target and source may not be entities that can also be complexTypes.
function updatePropertyFromRawEntity(dp, target, rawSource) {
var val = getPropertyFromRawEntity(rawSource, dp);
if (val === undefined) return;
if (dp.isComplexProperty) {
var coVal = target.getProperty(dp.name);
dp.dataType.dataProperties.forEach(function (cdp) {
// recursive call
updatePropertyFromRawEntity(cdp, coVal, val);
});
} else {
target.setProperty(dp.name, val);
}
}
rawSource 参数是一个数组(在 complexTypes 的情况下)是一个对象数组。所以问题是在调用 getPropertyFromRawEntity() 时,它传递的是一个数组而不是一个对象:
function getPropertyFromRawEntity(rawEntity, dp) {
var propName = dp.nameOnServer || dp.isUnmapped && dp.name;
return parseValueForDp(rawEntity[propName], dp);
}
因此 rawEntity[propName] 将始终未定义,因为它是一个数组。