Hide control before data received

问题: I have UI5 button. This button is set to visible, based on certain data coming from backend. Hence, I have set visibility of button in onDataReceived function in controll...

问题:

I have UI5 button. This button is set to visible, based on certain data coming from backend.

Hence, I have set visibility of button in onDataReceived function in controller file.

<Button id="idButton" visible="{HoldButtonVisiblity>/HoldButtonVisible}"/>

Code in controller:

onDataReceived: function (oEvent) {
    var sHoldVisible = aData[0].activeFlag;
    if(sHoldVisible) {
        //make button visible
    } else {
        //make button invisible
    }
}

This works fine. However, the issue is, when I start the app it takes 3-4 seconds for data to load in worklist view. During this time, the button is still visible to the user. It gets invisible after data is received.

My question is, how can I hide button on app initialization? I tried this piece of code:

<Button id="idButton" visible="false"/>

However, if I give visible=false in the view file, button never becomes visible even if it satisfies conditions to be visible.


回答1:

I think that you should add more information in order to fix your problem. Is your HoldButtonVisiblity JSONModel initialized at start?

What you should do is to init it (in your manifest.json or Component.js) like:

{
    "HoldButtonVisible": false
}

and than

onDataReceived: function (oEvent) {
    var sHoldVisible = aData[0].activeFlag;
    this.getView().getModel("HoldButtonVisiblity").setProperty("/HoldButtonVisible", sHoldVisible);
}

Please note that I've used your code but I don't know from where you're getting the aData information and I don't know the value type of activeFlag. If it's not a boolean please convert it.


回答2:

You need to initialize HoldButtonVisible in your HoldButtonVisiblity model to false. While it is undefined, the button is still visible.

  • 发表于 2019-01-22 15:05
  • 阅读 ( 212 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除