微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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";
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?