Polymerのカスタム要素である<general-element>
に含まれるJavascriptメソッドにアクセスしようとしています。この要素には、パネルを開閉するための関数が含まれています。入れ子になったPolymerのカスタム要素内のJavaScriptメソッドにアクセス
この一般的な要素は、より具体的な要素内で使用されます(例:<specific-element></specific-element>
)。特定の要素には汎用要素が含まれており、パネルタイトルなどの属性を追加します。
ただし、<specific-element>
をページ内で使用すると、その中から開く/閉じるメソッドを呼び出すことができません。私は間違った方法でこれに近づいていますか?これを行う方法はありますか?
編集:コード例
は、いくつかのポリマーコードを削除した - の例は、単に要素が一緒に
一般的な要素どのように動作するかを示すために:
<dom-module id="general-element">
<template>
// Code to define a slide-in panel
</template>
<script>
_openPanel: function() {
//Apply class to make panel visible
},
_closePanel: function() {
// Apply class to hide panel
}
</script>
</dom-module>
特定の要素:
<dom-module id="specific-element">
<template>
<general-element title="Administration Panel" >
<h1>Hello</h1>
</general-element>
</template>
</dom-module>
用法:
<dom-module id="admin-page">
<template>
<button on-click="openPanel"></button>
<specific-element></specific-element>
</template>
<script>
openPanel: function() {
// Trying to call general-element _openPanel method
}
</script>
</dom-module>
私がここでやろうとしているのは、すでに一般的な要素で説明したopenPanelの動作です。これは、パネルが複数の場所で使用されるためです。同じ方法で動作するので、特定のパネルのオープン/クローズ方法を実装し続けるのは意味がありません。
は、いくつかの実際のコードはいいだろう動作するはずです。 –
@GünterZöchbauerコード例を追加しました – Vanita