访问附件中dom

编程入门 行业动态 更新时间:2024-10-23 07:34:26
本文介绍了访问附件中dom-repeat内部的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想访问dom-repeat内部的元素.在这里,el返回空数组:

<dom-module id="child-element"> <template> <div id="ida"> <ul> <template is="dom-repeat" items="{{user}}" id="items"> <li class = "classa">{{item.name}}</li> </template> </ul> </div> </template> <script> ChildElement = Polymer({ is: 'child-element', factoryImpl(users) { this.user = users; }, properties: { user: { type: Array } }, attached: function() { var el = Polymer.dom(this.root).querySelectorAll("#ida .classa"); console.log("el",el); } }); </script> </dom-module>

如何从Polymer的其他位置访问dom-repeat内部的动态创建的元素?

此处是完整版本的链接.

解决方案

调用后,可能尚未初始化子级.将代码包装在异步函数中.

attached:function(){ this.async(function() { // access sibling or parent elements here var el = Polymer.dom(this.root).querySelector("#ida .classa"); console.log("el",el); }); }

开发人员指南中对此进行了记录

I would like to to have access to the elements inside of a dom-repeat. Here, el returns empty array:

<dom-module id="child-element"> <template> <div id="ida"> <ul> <template is="dom-repeat" items="{{user}}" id="items"> <li class = "classa">{{item.name}}</li> </template> </ul> </div> </template> <script> ChildElement = Polymer({ is: 'child-element', factoryImpl(users) { this.user = users; }, properties: { user: { type: Array } }, attached: function() { var el = Polymer.dom(this.root).querySelectorAll("#ida .classa"); console.log("el",el); } }); </script> </dom-module>

How can I access the dynamically created elements inside the dom-repeat from elsewhere in Polymer?

Here is a link to the the full version.

解决方案

When attached is called the children may not be initialized yet. Wrap your code in an async function.

attached:function(){ this.async(function() { // access sibling or parent elements here var el = Polymer.dom(this.root).querySelector("#ida .classa"); console.log("el",el); }); }

This is documented in the Developer guide

更多推荐

访问附件中dom

本文发布于:2023-08-02 11:28:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277438.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:附件   dom

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!