查找与 dom

编程入门 行业动态 更新时间:2024-10-21 20:28:33
本文介绍了查找与 dom-repeat 的特定实例关联的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个自定义元素,可以在页面上生成一个大的月历.这是用一对嵌套的 dom 创建的,外层重复提供每月的每周,内层提供一周内的天数.最初这开始时相当空,但随后 ajax 请求返回填充模型的数据,每天提供更多的数据.当用户单击某一天时,我将(刚刚开始实施它)打开一个对话框,其中包含有关该特定日期的更多信息.我可以将此对话框放在适当的日期旁边,因为点击事件将点击的目标作为属性,并且我可以将其传递给纸张对话框的 positionTarget 属性.我在其他地方做过这个,效果很好.

I have a custom element that generates a large monthly calendar on the page. This is created with a pair of nested dom-repeats the outer one providing each week of the month and the inner one providing the days within the week. Initially this starts out quite empty, but then a ajax request returns with data which fills in the model, providing considerably more data for each day. When a user clicks on one of the days I will (just started to implement it) open a dialog box with much more information about that particular day. I can position this dialog box just beside the appropriate day because the tap event has the target of the tap as a property, and I can pass that to the positionTarget property of the paper dialog. I have done this elsewhere and it works a treat.

在这种特殊情况下,可以通过 url 中的可选参数选择特定日期,由 app-route 解析.因此,我还想在输入特定 url 时打开正确定位的对话框.

In this particular case the particular day can be selected by an optional parameter in the url, parsed by app-route. So I also would like to open the dialog box, positioned correctly, when a particular url is entered.

我可以轻松地在用于日历的模型中找到基础记录,但问题是如何找到与模型特定部分相关联的元素.

I can easily locate the underlying record in the model used for the calendar, but the question is how can I locate the element that is associated with a particular part of the model.

推荐答案

事实证明,解决这个问题的方法相对简单.

It turns out the solution to this is relatively easy.

在您想要获取其实例的元素上,公开一个表示某种意义的属性,其值对于该元素的每个副本都是唯一的.就我而言,它是日期"

On the element you want to get its instance of expose an attribute that means something, with a value that is unique to each copy of the element. In my case it was "date"

所以我有类似(简化)的东西

so I had something like (simplified)

<template is="dom-repeat" items="{{week}}" as="day"> <li urlday$="[[day.date]]"> ... </li> </template>

然后在我的代码中选择打开我所做的对话框

then in my code to select open the dialog I did

this.$.mydialog.positionTarget = this.$$('[urlday="' + date + '"]'); this.$.mydialog.open();

更多推荐

查找与 dom

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

发布评论

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

>www.elefans.com

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