在light DOM树上运行选择器并访问它
Running a selector on, and visiting, the light DOM tree
我有一个类似的小部件:
<link rel="import" href="../polymer/polymer.html">
<dom-module id="hot-network">
<template>
<style>
:host {
display: block;
}
</style>
<content id="content"></content>
</template>
<script>
Polymer({
is: 'hot-network',
attached: function(){
var form = this.queryEffectiveChildren( 'iron-form');
var paperInput = this.queryEffectiveChildren( 'paper-input');
console.log("WIDGETS:", ironAjaxWidgets );
},
});
</script>
</dom-module>
我想像这样使用这个小部件:
<dom-module id="my-view2">
<template>
<hot-network>
<div>
<form is="iron-form" id="form" on-iron-form-response="_response" method="PUT" action="/stores/polymer">
<paper-input required id="name" name="name" label="Your name"></paper-input>
<paper-button raised type="submit">Click!</paper-button>
</form>
</div>
</hot-network>
</template>
<script>
Polymer({
is: 'my-view2',
_response: function(){
console.log("AH!");
}
});
</script>
</dom-module>
问题1:如何在light DOM中查找元素(使用选择器)
这两个电话实际上不起作用:
var form = this.queryEffectiveChildren( 'iron-form');
var paperInput = this.queryEffectiveChildren( 'paper-input');
因为他们只在有效的孩子的"第一级"上运行选择器。
如果我需要在分布式内容中寻找小部件(对合成很重要),我如何可靠地做到这一点?
问题2:探访所有有效率的孩子的最佳方式是什么
我想出了这个代码,但它近乎淫秽。。。我看着它都会觉得好笑!
attached: function(){
this.async( function(){
function inspect( e ){
console.log("INSPECTING", e );
}
this.getEffectiveChildren().forEach( (effectiveChild) => {
console.log("Effective child found.");
inspect( effectiveChild );
console.log("Getting into all children of it...");
var foundChildren = effectiveChild.getElementsByTagName("*");
for( var i = 0, l = foundChildren.length; i < l; i ++ ){
var child = foundChildren[ i ];
inspect( child );
};
console.log("All children inspected!");
});
});
},
问题1:
var form = Polymer.dom(this.root).querySelector('#form');
// or
var form = this.$$('#form');
// or if you wanna use tags/attributes
var form = Polymer.dom(this.root).querySelector('form[is="iron-form"]');
查询纸张输入类似于上面的操作。
相关文章:
- Rally App SDK 1.32:在最近的重组后,选择器无法使用通用查询访问PortfolioItems
- AUI日期选择器:如何访问当前元素
- 是否有可能访问JSON对象中列出的jQuery选择器
- 有没有更好的方法来访问用JQuery选择器选择的第一个元素
- 未定义访问具有对象属性的jquery选择器
- 主干视图可以't访问jQuery选择器
- 无法使用 jQuery 选择器访问单击事件
- 访问 Jquery 选择器作为对象属性,意外结果
- 如何从jQuery选择器访问javascript方法
- 如何在访问选择器后访问 css 选择器属性
- 使用 JQuery 在不涉及整页刷新的动态页面更改后访问/传播选择器到新的输入字段
- 如何访问jQuery中新的伪选择器中的参数
- 如何访问选择器上jquery中的父级
- 无法't使用jquery选择器访问输入
- 为什么我不能访问CoffeeScript中的动态内容选择器
- 日期选择器的文本框访问权限
- 使用存储在变量中的选择器访问DOM元素
- Jquery选择器访问锚从与表
- 下拉选项不能使用jquery选择器访问
- jQuery插件选择器访问范围