vde*_*nne 8 polymer polymer-1.0
我有我的元素:
<dom-module id="x-el">
<p class="special-paragraph">first paragraph</p>
<content></content>
</dom-module>
Run Code Online (Sandbox Code Playgroud)
我喜欢它
<x-el>
<p class="special-paragraph">second paragraph</p>
</x-el>
Run Code Online (Sandbox Code Playgroud)
在我的命令部分:
Polymer({
is: 'x-el',
ready: function () {
/* this will select all .special-paragraph in the light DOM
e.g. 'second paragraph' */
Polymer.dom(this).querySelectorAll('.special-paragraph');
/* this will select all .special-paragraph in the local DOM
e.g. 'first paragraph' */
Polymer.dom(this.root).querySelectorAll('.special-paragraph');
/* how can I select all .special-paragraph in both light DOM and
local DOM ? */
}
});
Run Code Online (Sandbox Code Playgroud)
是否有可能使用Polymer内置的?或者我应该使用默认的DOM API?
Ada*_*ian 12
聚合物并不能提供一个辅助函数或抽象,它会列出从光节点和本地的DOM.
如果您需要此功能,则可以使用this.querySelector(selector).
另外,除了Polymer.dom(this.root).querySelectorAll(selector)方法之外,Polymer还提供了$$实用函数,它有助于访问元素本地DOM的成员.此功能使用如下:
<dom-module id="my-element">
<template>
<p class="special-paragraph">...</p>
<content></content>
</template>
</dom-module>
<script>
Polymer({
is: 'my-element',
ready: {
this.$$('.special-paragraph'); // Will return the <p> in the local DOM
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
请注意,与函数不同querySelectorAll,该$$函数只返回一个元素:本地DOM中与选择器匹配的第一个元素.
| 归档时间: |
|
| 查看次数: |
10419 次 |
| 最近记录: |