0

我发现了一个关于 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] 将始终未定义,因为它是一个数组。

4

1 回答 1

0

Breeze ComplexType 具有由元数据指定的良好定义的结构。任何属性(除了)键都可以使其数据类型为 complexType。但是,我认为您想要的是“无类型”结构。这可以通过将属性定义为具有“未定义”的数据类型来完成,例如:

  var newProp = new DataProperty({
                name: "Foo"
                dataType: DataType.Undefined,
                isNullable: true,
                isUnmapped: true
            });
  entityType.addProperty(newProp);

“未定义”数据类型将接受任何类型和结构的数据。

于 2013-05-13T17:46:10.823 回答