OpenUI5 格式化程序对模型更改没有反应
OpenUI5 formatter not reacting on model change
我尝试实现一个格式化程序,以便在两个模型变量为真时将按钮设置为可见,因此我使用父模型对象作为格式化程序的路径,例如:
<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)时,不会调用格式化程序并且按钮仍然是 in/visible。
...
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', type: 'sap.ui.model.type.Boolean', formatter: '.checkIfVisibleFormatter'}" />
我如何确保每次 uiSwitch 发生变化时都会调用格式化程序?
尝试将格式代码更改为:-
<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;
}
此外,请确保在 bootstrap 中启用复杂绑定。
这应该可以解决问题。
Off-topic,当你想修改模型中的数据时,尝试使用语法:-
this.getOwnerComponent().getModel("myModel").setProperty("/uiSwitches/switch1",false);
我尝试实现一个格式化程序,以便在两个模型变量为真时将按钮设置为可见,因此我使用父模型对象作为格式化程序的路径,例如:
<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)时,不会调用格式化程序并且按钮仍然是 in/visible。
...
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', type: 'sap.ui.model.type.Boolean', formatter: '.checkIfVisibleFormatter'}" />
我如何确保每次 uiSwitch 发生变化时都会调用格式化程序?
尝试将格式代码更改为:-
<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;
}
此外,请确保在 bootstrap 中启用复杂绑定。 这应该可以解决问题。
Off-topic,当你想修改模型中的数据时,尝试使用语法:-
this.getOwnerComponent().getModel("myModel").setProperty("/uiSwitches/switch1",false);