PCF控件的值并不总是加载;是比赛条件,还是其他?我怎么知道?

问题描述

是否有人在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();
    }

解决方法

结果是,您需要在updateView函数中设置HTMLElement的值!

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

Reference,感谢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";
        }
    }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...