0

有没有其他人在 Power Apps 组件框架 (PCF) 的初始化中看到未设置控件值的竞争条件?

我将如何进行测试?

加载表单时(在 UCI 中)我没有看到 API 调用?我确实在网格视图的批处理调用中看到了它,但一定不是吗?

这是我的代码:

public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLDivElement) {
        this.context = context;
        this.container = document.createElement("div");
        this.container.setAttribute("class", "acgContainer")
        this._refreshIndex = this.refreshIndex.bind(this);
        this.notifyOutputChanged = notifyOutputChanged;
        this.value = context.parameters.acgAriasYesNoUnControl.raw;
        //console.log("the init value: ", this.value);
        this.options = context.parameters.acgAriasYesNoUnControl.attributes?.Options;
        //console.log(this.options);
        this.selectElement = document.createElement("select");
        this.selectElement.addEventListener('change', this._refreshIndex);
        // @ts-ignore
        var zeroEle = this.selectElement.appendChild(new Option("---", null));
        zeroEle.style.backgroundColor = "#ffffff";
        if (this.options) {
            if (this.options.length > 0) {
                this.options.map((option: ComponentFramework.PropertyHelper.OptionMetadata, index: number) => {
                    var ele = this.selectElement.appendChild(new Option(option.Label, option.Value.toString()));
                    ele.style.backgroundColor = "#ffffff";
                    if (option.Label === this.envYesValue) {
                        //console.log("green option: ", option.Value);
                        this.valueOfYes = option.Value;
                    }
                    if (this.value === option.Value) {
                        ele.dataset.selected = "true";
                    }
                })
            }
        }
        // @ts-ignore
        this.selectElement.value = this.value?.toString() || null;
        this.selectElement.setAttribute("class", "acgYesNoUnControl");
        this.container.appendChild(this.selectElement);
        container.appendChild(this.container);
        //this.notifyOutputChanged();
    }
4

1 回答 1

0

原来,您需要在 updateView 函数中设置 HTMLElement 的值!

init 方法最初可能不会设置该值,因为它可能没有来自服务器的值。但是 updateView 函数在每次看到新值时都会运行,并且会更新 HTMLElement。

参考,感谢Diana BGreg Hurlman

所以,我应该突出显示 updateView 函数:

public updateView(context: ComponentFramework.Context<IInputs>): void {
        this.context = context;
        // storing the latest context from the control.
        // @ts-ignore
        this.selectElement.value = context.parameters.acgAriasYesNoUnControl.raw
            ? context.parameters.acgAriasYesNoUnControl.raw
            : null;
        this.value = context.parameters.acgAriasYesNoUnControl.raw
            ? context.parameters.acgAriasYesNoUnControl.raw
            : null;
        if (this.value === this.valueOfYes) {
            this.selectElement.style.backgroundColor = "#8cbd18";
        } else {
            this.selectElement.style.backgroundColor = "#ffffff";
        }
    }
于 2020-08-26T20:24:06.463 回答