【问题标题】:How to get the CheckBox's, 'selected' attribute to trigger it's select method [SAPUI5]如何获取 CheckBox 的“选定”属性以触发它的选择方法 [SAPUI5]
【发布时间】:2021-08-15 17:24:00
【问题描述】:

我有一个五行表,带有一个标签 + CheckBox。当手动选择 CheckBox(触发选择事件处理程序)时,它会为整行着色灰色,取消选择它会导致颜色被移除。如果它是由模型通过selected 上的属性绑定完成的,它不会触发选择事件处理程序onCheckBoxSelection 并且行颜色不会改变。

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

问题:如何通过selected上的属性绑定来触发事件处理程序onCheckBoxSelection,以便选中复选框时颜色发生变化?

【问题讨论】:

    标签: javascript xml sapui5


    【解决方案1】:

    我建议使用您当前用于更改行颜色的所有逻辑创建一个新函数。然后您的 EventHandler onCheckBoxSelected 应该使用新创建的函数。

    然后您可以使用模型事件propertyChange。创建一个新的 EventHandler 例如onPropertyChange 并从那里调用新创建的函数。

    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
    }
    

    【讨论】:

    • 感谢您的评论。我相信有一点误解。我正在加载一个模型,它已经具有带有值的属性“状态”,它完成了所有的选择。我不打算更改任何属性/值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2021-04-19
    • 1970-01-01
    • 2021-08-15
    相关资源
    最近更新 更多