我正在尝试访问Polymer自定义元素中包含的Javascript方法<general-element>
。该元素包含用于打开和关闭面板的功能。
该常规元素用于更具体的元素中,例如:<specific-element></specific-element>
。特定元素包含常规元素并向其添加属性,例如:面板标题等。
但是,在<specific-element>
页面内使用时,无法通过它调用任何打开/关闭方法。我是从错误的方式来处理这个问题吗,有没有办法做到这一点?
编辑:代码示例
删除了一些Polymer代码-示例只是为了展示元素如何协同工作
一般元素:
<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行为,正如一般元素中已经描述的那样。这是因为该面板将在多个地方使用,所以继续为特定面板实施打开/关闭方法是没有意义的,因为它们将以相同的方式工作。
这应该工作
openPanel: function() {
// Trying to call general-element _openPanel method
$$('specific-element').$$('general-element')._openPanel();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句