作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的小部件:
<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!");
});
});
},
最佳答案
问题 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"]');
查询paper-input与上面类似。
关于javascript - 在轻量 DOM 树上运行选择器并访问它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38517721/
Go协程为并发编程提供了强大的工具,结合轻量级、高效的特点,为开发者带来了独特的编程体验。本文深入探讨了Go协程的基本原理、同步机制、高级用法及其性能与最佳实践,旨在为读者提供全面、深入的理解
已结束。此问题正在寻求书籍、工具、软件库等的推荐。它不满足Stack Overflow guidelines 。目前不接受答案。 我们不允许提出寻求书籍、工具、软件库等推荐的问题。您可以编辑问题,以便
Lubuntu 20.04 LTS 与之前的 LTS 版本有很大的不同。它旨在给你一个更完善的体验,而不仅仅是关注旧电脑。请阅读更多关于 Lubuntu 20.04 的内容。 Lubuntu
我是一名优秀的程序员,十分优秀!