当Polymer元素中的bool属性更改时如何使用排序重新运行dom

编程入门 行业动态 更新时间:2024-10-23 19:31:29
本文介绍了当Polymer元素中的bool属性更改时如何使用排序重新运行dom-repeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当元素中的某些内容发生更改时,或者无论何时我希望从代码中自动获取代码时,如何重新运行排序和呈现元素?谢谢

How can I rerun sort and render element when something changed in my element or whenever I want from code or automatically? Thank you

<template is="dom-repeat" items="[[attachments]]" as="attach_item" sort="_sortItems"></template>

推荐答案

您需要为要观看的字段设置观察者.

You need to set an observer for the fields you want to watch.

引自聚合物文档:

默认情况下,过滤器和排序功能仅在数组本身发生突变(例如,通过添加或删除项)时才运行.

By default, the filter and sort functions only run when the array itself is mutated (for example, by adding or removing items).

要在某些项目子字段更改时重新运行过滤器或排序功能,请将observe属性设置为以空格分隔的项目子字段列表,这将导致列表被重新过滤或重新排序

To re-run the filter or sort functions when certain sub-fields of items change, set the observe property to a space-separated list of item sub-fields that should cause the list to be re-filtered or re-sorted.

示例:

<template is="dom-repeat" items="{{employees}}" filter="isEngineer" observe="type manager.type">

此处有更多信息: https: //www.polymer-project/1.0/docs/devguide/templates.html#filtering-and-sorting-lists

PS:您需要使用this.set("array.index.field",value)设置字段,否则不会通知您的观察者

PS: you need to set your field using this.set("array.index.field", value), otherwise your observer won't be notified

更多推荐

当Polymer元素中的bool属性更改时如何使用排序重新运行dom

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

发布评论

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

>www.elefans.com

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