Egret-我的探索:exml自定義組件中通過ID獲取子組件實例


 

可以看到,在exml編輯器中我們給UI組件添加了ID屬性;

之后在對應的 ts文件中使用這個組件

namespace ui {
    export class GameCtrl extends eui.Component {
        constructor() {
            super();
            this.skinName = "resource/eui_skins/GameMainCtrl.exml";
            this.addEventListener(eui.UIEvent.COMPLETE, this.ctrlInit, this);
        }
        private ctrlInit(): void {
            console.log("GameCtrl加載完成", this.TabMain);
        }
        private TabMain:eui.ViewStack;
    }
}

注意紅色加粗部分,  定義同名屬性取到組件實例

輸出結果如下:

GameCtrl加載完成 ViewStack {$hashCode: 1911, $EventDispatcher: {…}, $children: Array(5), $name: "", $parent: GameCtrl, …}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM