Packagenameによるビューインスタンスの識別方法


クラフトのインスタンス.UIビューはDOMツリーに一意のIDで配置されます.
ウィンドウオブジェクトに登録されます.idはインスタンスメソッド呼び出しに使用されます.
インスタンスIDは常に同一です.しかし、そのID式でインスタンスを識別できるようにするには、packagename クラス変数.

packagenameなしで


class Example extends Craft.UI.View {
    template(componentId){
        return `
            <div id="root" class="root">
                Hello World!
            </div>
        `;
    }
}

var view = new Example();
view.loadView();
Craft.Core.Context.getRootViewController().appendSubView(view);
このクラスは次のように配置されます.

exampleクラスのインスタンスはExample_2 , 末尾のシリアル番号を持つクラス名.例クラスのインスタンスを追加したり、別のパッケージにクラスクラスを追加しても、アプリケーション全体で一意です.

を使って


インスタンスによってインスタンスのクラスを識別するには、Packagenameクラス変数を使用できます.
class Example extends Craft.UI.View {
    constructor(options){
        super(options);
        this.packagename = 'craftkit.devtoblog.Example';
    }
    template(componentId){
        return `
            <div id="root" class="root">
                Hello World!
            </div>
        `;
    }
}

var view = new Example();
view.loadView();
Craft.Core.Context.getRootViewController().appendSubView(view);
これは次のようになります.

この場合、exampleクラスのインスタンスはcraftkit_devtoblog_Example_4 .
インスタンスプールを調査するためにこれを使用できます.

ノート


The packagename はモジュール名自体によって制限されません.