Difference Between this.getView().byId(), this.byId(), and sap.ui.getCore().byId()

前端 未结 1 1278
滥情空心
滥情空心 2020-12-11 09:50

Can I know the difference and performance when I use:

const myControl = this.getView().byId("myIDhere");
cons         


        
相关标签:
1条回答
  • 2020-12-11 10:11
    • this.getView().byId(...) is equivalent to this.byId(...). Take a look at the source code to see what byId does:

      // sap.ui.core.mvc.Controller
      Controller.prototype.byId = function(sId) {
        return this.oView ? this.oView.byId(sId) : undefined;
      };
      

      As you can see, this.byId is just a shortcut for this.getView().byId. They both can be used to access controls defined in the view. E.g.:

      this.byId("myPanel");
      
    • sap.ui.getCore().byId(...)API, on the other hand, awaits a fully concatenated global ID which is why you cannot simply exchange this.byId with sap.ui.getCore().byId if the target control is a view descendant.

      sap.ui.getCore().byId("__xmlview0--myPanel"); // <-- Please don't do that!
      

    More about IDs:

    • Stable IDs: All You Need to Know
    • For the sake of completeness: How to Access Elements from XML Fragment by ID
    0 讨论(0)
提交回复
热议问题