简体   繁体   English

如何获取 CheckBox 的“选定”属性以触发它的 select 方法 [SAPUI5]

[英]How to get the CheckBox's, 'selected' attribute to trigger it's select method [SAPUI5]

I have a Table of five rows, with a label + CheckBox.我有一个五行表,带有一个 label + CheckBox。 When the CheckBox is selected manually(which triggers the selection event handler), it does color the whole row grey , and deselecting it leads to the removal of the color.当手动选择 CheckBox (触发选择事件处理程序)时,它会将整行着色为gray ,取消选择它会导致颜色被移除。 If it's done via property binding on selected by the model, it doesn't trigger the selection event handler onCheckBoxSelection and the row color doesn't change.如果它是通过 model selected的属性绑定完成的,它不会触发选择事件处理程序onCheckBoxSelection并且行颜色不会改变。

<CheckBox selected="{= ${modelExample>State} === 1}" enabled="true" select="onCheckBoxSelection"/>

Question : How to trigger the event handler onCheckBoxSelection via the property binding on selected so that the color changes when the checkbox is selected?问题:如何通过 selected 上的属性绑定触发事件处理程序onCheckBoxSelection ,以便在selected复选框时颜色发生变化?

I would suggest creating a new function with all the logic you currently use to change the row color.我建议使用您当前用于更改行颜色的所有逻辑创建一个新的 function。 Your EventHandler onCheckBoxSelected should then use the newly created function.然后,您的 EventHandler onCheckBoxSelected应使用新创建的 function。

Then you can use the Model event propertyChange .然后您可以使用 Model 事件propertyChange Create a new EventHandler eg onPropertyChange and call the newly created function from there.创建一个新的 EventHandler 例如onPropertyChange并从那里调用新创建的 function。

onInit: function() {
    // attach the event handler to the model
    this.getView().getModel("modelExample").attachPropertyChange(this.onPropertyChange.bind(this));
},

onCheckBoxSelected: function(oEvent) {
    // call the newly created function
    this._handleSelectionChange(...);
},

onPropertyChange: function(oEvent) {
    // only call the new selection change function if the correct property is changed
    if (oEvent.getParameter("path") === "State") {
        this._handleSelectionChange(...);
    }
},

_handleSelectionChange: function(...) {
    // your code to change the row color
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM