w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
SAPUI5: Binding controller properties to the view

UI5 follows the M-V-C paradigm and event handler is not part of data model.

The correct way to do data binding is as following:

View:

The onClick is defined as a function in the controller not in the data model.

<custom-button id="btn" value="{/value}"
disabled="{/disabled}" click="onClick" />

Controller:

sap.ui.core.mvc.Controller.extend('...', {

    buttonProps: new sap.ui.model.json.JSONModel({
        value: 'cheese',
        disabled: 'disabled'
    }),

    onInit: function() {
        this.byId('btn').setModel(this.buttonProps);
    },

    onClick:function(oEvent) {

    }    

});




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.