【问题标题】:Breeze.js rejectChanges deletes non-scalar complex typesBreeze.js rejectChanges 删除非标量复杂类型
【发布时间】:2014-05-04 00:26:50
【问题描述】:

当我对具有复杂类型的非标量属性的实体调用 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

【问题讨论】:

  • 我明天会试着看看这个。
  • @JayTraband 如果你有机会看到这个,请告诉我 - 如果需要,我可能可以在 jsBin 或其他东西中重新创建。
  • 对不起,被埋葬了……再创造会很棒;)

标签: knockout.js breeze


【解决方案1】:

我复制了这个问题并修复了它。当第二次从服务器获取实体时会出现此问题,导致调用 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);
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-28
    • 1970-01-01
    • 2010-09-21
    • 2014-12-31
    • 2016-11-28
    相关资源
    最近更新 更多