如何解决OpenUI5格式化程序对模型更改无反应
我试图实现一个格式化程序,以在两个模型变量为true时将按钮设置为可见,因此我将父模型对象用作格式化程序的路径,例如:
<Button text="Button" visible="{path: 'myModel>/uiSwitches',type: 'sap.ui.model.type.Boolean',formatter: '.checkIfVisibleFormatter'}" />
我的格式化程序看起来像这样:
checkIfVisibleFormatter: function(uiSwitches) {
return uiSwitches.switch1 && uiSwitches.switch2;
}
现在,通过getModel()和setData()更改模型值(switch1或switch2)时,不会调用格式化程序,并且按钮仍处于/可见状态。
...
let myModel = this.getOwnerComponent().getModel("myModel");
let myData = myModel.getData();
myData.uiSwitches.switch1 = false;
myModel.setData(myData);
...
如果我直接在按钮内部引用这些模型标志之一,则ui至少会在对此标志进行更改时刷新。
<Button text="Button {myModel>/uiSwitches/switch1}" visible="{path: 'myModel>/uiSwitches',formatter: '.checkIfVisibleFormatter'}" />
如何确定每次uiSwitches内部的任何更改都会调用格式化程序?
解决方法
尝试将格式代码更改为:-
<Button text="Button" visible="{
parts : [
{ path: 'myModel>/uiSwitches/switch1',type: 'sap.ui.model.type.Boolean'},{ path: 'myModel>/uiSwitches/switch2',type: 'sap.ui.model.type.Boolean'}
],formatter: '.checkIfVisibleFormatter'
}" />
和格式化程序功能为:-
checkIfVisibleFormatter: function (switch1,switch2) {
return switch1 && switch2;
}
此外,请确保在引导程序中启用了复杂绑定。 这应该可以解决问题。
离题,当您要修改模型中的数据时,请尝试使用语法:-
this.getOwnerComponent().getModel("myModel").setProperty("/uiSwitches/switch1",false);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。