我有一个像这样的小部件:
<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>
这两个电话有效无效:
var form = this.queryEffectiveChildren( 'iron-form');
var paperInput = this.queryEffectiveChildren( 'paper-input');
因为他们只在有效孩子的“第一级”上运行选择器。
如果我需要在分布式内容中查找小部件(对于合成很重要),我该如何可靠地完成它?
我已经提出了这个代码,但这是一个边缘性的淫秽......我甚至看不到它,而且我的肚子里没有感觉好笑!
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!");
});
});
},
答案 0 :(得分:0)
问题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"]');
查询纸张输入与上述类似。