あまり詳しく説明しなくても、カスタムJavaScriptで2つの異なるタブセットを管理しようとしているプラグインがあります。オブジェクトが初期化されると、ページレイアウトからオブジェクトにペイン
を追加する必要があります。何かのようなもの:
this.$pane = new Craft.Pane($(".pane"));
そのコード行はちょっとした作品です。ただし、ページにコンソールレポートがロードされると、次のようになります。
Double-instantiating a pane on an element
上記のコード行を削除すると、コンソールログメッセージが消えてしまいます。$ {pane} = new Craft.Pane($(
“。pane”));
コード行ではいくつかのことが働きます。コード行がなければ、他のものが動作します。私はすべてのものが同時に働くことが必要です。
I’m struggling to know the right question to ask, so please
point me in the right direction if I am off the mark. Is it
possible to check if there is an existing Craft.Pane
object that exists before I try to create a new
object?
Craft.Pane
ベストアンサー
私は要素を再インスタンス化する前に、枠が存在するかどうかを調べることによってこれを解決できました。もし誰かがもっとうまくやっていることを説明できれば、別の答えを考えてもいいです。今のところ、次のように動作しました。
// Check to see if an element was already registered as a `Craft.Pane`:
if (!$("#myelement.pane").data('pane'))
{
//Create a pane object if it is not
this.$pane = new Craft.Pane($("#myelement.pane"));
}
else
{
//Use the existing pane object if it exists
this.$pane = $("#myelement.pane").data('pane');
}