Breezejs ComplexType 不执行自定义初始值设定项函数

Breezejs ComplexType not executing a custom initializer function

本文关键字:函数 ComplexType 执行 自定义 Breezejs      更新时间:2023-09-26

我最近更新到 Breezejs 1.4.2,运行自定义初始值设定项似乎存在问题。 我的应用程序使用 Breeze(我相信)正确注册了 ctor 和初始值设定项,但是当我从实体框架支持的 webapi 检索记录时,初始化器没有执行。 从 github 的签入源来看,初始化器代码似乎已被注释掉,并带有一条注释,即初始化器将从另一段代码执行。 任何想法我如何解决这个问题? 我可能会降级到 1.4.1,因为它正在工作。 我将删除注释掉的部分,看看它是否有效,但想知道是否有其他人遇到同样的事情?

C#

public class ForecastItem
{
    public int Id { get; set; }
    public Result CurrentYear { get; set; }
    /* extra detail removed */
}

public class Result 
{
    public int? Actual { get; set; }
    public int? Estimate { get; set; }
}

爪哇语

    function extendResult(metadataStore) {
        var ctor = function () { };
        var initialiser = function (entity) {
            entity.useEstimate = ko.computed({
                read: function () {
                    return entity.actual() === -1 ? true : false;
                },
                deferEvaluation: true
            });
            return entity;
        };
        metadataStore.registerEntityTypeCtor('Result', ctor, initialiser);
    }

编辑
我已经从breeze.debug中取消注释掉了代码.js它现在可以工作了。

ComplexType proto obejct

proto._createInstanceCore = function (parent, parentProperty ) {
    var aCtor = this.getCtor();
    var instance = new aCtor();
    new ComplexAspect(instance, parent, parentProperty);
    // TODO: don't think that this is needed anymore - createInstance call will do this 
    //if (parent) {
    //    this._initializeInstance(instance);
    //}
    return instance;
};

好的,这是一个错误,已得到修复。该修复程序将在 Breeze 1.4.3 中提供,或者现在可从 Breeze Git 存储库获得。...并感谢您找到它。:)