如何将组合框的输入设置为只读
How to set the input of a combobox to read-only
在我的一个 UI5 对话框中,我实现了一个组合框,它在初始加载屏幕时是不可见的。
在方法 onAfterRendering
中,我首先将输入设置为只读:
onAfterRendering: function(oEvent) {
var oShovel = this.getView("View0200").byId("comboShovel");
oShovel.$().find("input").attr("readonly", true);
this.setVisibleByListKey();
},
调用方法 setVisibleByListKey
后,属性 visibleShovel
将被设置为 false。
setVisibleByListKey: function(oEvent) {
var oModel = this.getView("View0200").getModel("Data0200");
this.setVisibleByListKey1(oModel);
// ...
},
setVisibleByListKey1: function(oModel) {
oModel.setProperty("/visibleShovel", false);
},
属性 绑定到我的组合框中可见的属性。
由于这种行为,方法 onAfterRendering
将被再次调用,属性 readonly
不可用(因为不可见)。
<ComboBox id="comboShovel"
editable="true"
enabled="true"
visible="{Data0200>/visibleShovel}"
valueState="None"
change=".changeCombo">
<items>
<core:Item text="Ja" enabled="true" key="0" />
<core:Item text="Nein" enabled="true" key="1" />
<core:Item text="Nicht erforderlich" enabled="true" key="2" />
</items>
</ComboBox>
我试过调用onInit
或onBeforeRendering
中的set方法,但此时无法更改输入属性(因为再次隐身)。
那么当我设置命名可见时如何将组合框的输入设置为只读属性?
不使用 jquery,而是使用 UI5 控件的方法和属性:
sap.m.ComboBox borrows the following two methods from sap.m.InputBase:
或者由于您正在使用 属性 绑定来提高可见性,因此对可编辑的 属性 执行相同的操作,例如{Data0200>/editableShovel}
解决方案是使用 sap.m.Select
或为 sap.m.Combobox
实施 "change" 事件处理程序并使用类似于 this sample:[=15= 的编码]
handleChange: function(oEvent) {
var oValidatedComboBox = oEvent.getSource();
var sSelectedKey = oValidatedComboBox.getSelectedKey();
var sValue = oValidatedComboBox.getValue();
if (!sSelectedKey && sValue) {
oValidatedComboBox.setValueState("Error");
oValidatedComboBox.setValueStateText("Please enter a valid country!");
} else {
oValidatedComboBox.setValueState("None");
}
},
在我的一个 UI5 对话框中,我实现了一个组合框,它在初始加载屏幕时是不可见的。
在方法 onAfterRendering
中,我首先将输入设置为只读:
onAfterRendering: function(oEvent) {
var oShovel = this.getView("View0200").byId("comboShovel");
oShovel.$().find("input").attr("readonly", true);
this.setVisibleByListKey();
},
调用方法 setVisibleByListKey
后,属性 visibleShovel
将被设置为 false。
setVisibleByListKey: function(oEvent) {
var oModel = this.getView("View0200").getModel("Data0200");
this.setVisibleByListKey1(oModel);
// ...
},
setVisibleByListKey1: function(oModel) {
oModel.setProperty("/visibleShovel", false);
},
属性 绑定到我的组合框中可见的属性。
由于这种行为,方法 onAfterRendering
将被再次调用,属性 readonly
不可用(因为不可见)。
<ComboBox id="comboShovel"
editable="true"
enabled="true"
visible="{Data0200>/visibleShovel}"
valueState="None"
change=".changeCombo">
<items>
<core:Item text="Ja" enabled="true" key="0" />
<core:Item text="Nein" enabled="true" key="1" />
<core:Item text="Nicht erforderlich" enabled="true" key="2" />
</items>
</ComboBox>
我试过调用onInit
或onBeforeRendering
中的set方法,但此时无法更改输入属性(因为再次隐身)。
那么当我设置命名可见时如何将组合框的输入设置为只读属性?
不使用 jquery,而是使用 UI5 控件的方法和属性:
sap.m.ComboBox borrows the following two methods from sap.m.InputBase:
或者由于您正在使用 属性 绑定来提高可见性,因此对可编辑的 属性 执行相同的操作,例如{Data0200>/editableShovel}
解决方案是使用 sap.m.Select
或为 sap.m.Combobox
实施 "change" 事件处理程序并使用类似于 this sample:[=15= 的编码]
handleChange: function(oEvent) { var oValidatedComboBox = oEvent.getSource(); var sSelectedKey = oValidatedComboBox.getSelectedKey(); var sValue = oValidatedComboBox.getValue(); if (!sSelectedKey && sValue) { oValidatedComboBox.setValueState("Error"); oValidatedComboBox.setValueStateText("Please enter a valid country!"); } else { oValidatedComboBox.setValueState("None"); } },