Breeze.js rejectChanges删除非标量复杂类型

时间:2014-03-25 21:37:03

标签: knockout.js breeze

当我在具有复杂类型的非标量属性的实体上调用rejectChanges()时,它似乎正在删除所有这些复杂类型 -

metadataStore.addEntityType({
    shortName: "GrandParent",
    namespace: "Product",
    dataProperties: {
        id: { dataType: "String", isPartOfKey: true },
        someValues: { complexTypeName: "parentValue:#Product", isScalar: false }
    }
});

metadataStore.addEntityType({
    shortName: "ParentValue",
    namespace: "Product",
    isComplexType: true,
    dataProperties: {
        id: { dataType: "String" },
        text: { dataType: "String" },
        previousValue: { complexTypeName: "ChildValue:#Product", isScalar: true }
    }
});

metadataStore.addEntityType({
    shortName: "ChildValue",
    namespace: "Product",
    isComplexType: true,
    dataProperties: {
        value: { dataType: "String" },
        text: { dataType: "String" }
    }
});

我之前遇到的问题是将complexTypes添加到数组并调用cancelChanges会使列表中的complexTypes加倍 - 我现在可以重新查询服务器中的项目,但它似乎有点相关

Calling rejectChanges on a entity with collection of complexTypes doubles the complexTypes in collection

1 个答案:

答案 0 :(得分:0)

我复制了这个问题并修复了它。当从服务器第二次获取实体时会发生此问题,导致调用updateTargetFromRay方法,其中包含错误。

这是我的修复:

// mathieug: clearing this array before updating it will cause 
// the _origValues to be set to length = 0. It must thus be done after the
// first item is pushed to the array(a beforeChange method is called in 
// the push function)
// oldVal.length = 0; // comment this line
var initialLength = oldVal.length; // keep initial count
if (Array.isArray(rawVal)) {
     rawVal.forEach(function (rawCo) {
         var newCo = dataType._createInstanceCore(target, dp);
         dataType._updateTargetFromRaw(newCo, rawCo, rawValueFn);
         dataType._initializeInstance(newCo);
         oldVal.push(newCo);
     });

     // Remove initial items
     oldVal.splice(0, initialLength);
 }