如何解决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 B和Greg 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 举报,一经查实,本站将立刻删除。