简体   繁体   English

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

[英]How to re run dom-repeat with sort when bool property changed in Polymer element

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. 您需要为要观看的字段设置观察者。

Quoted from polymer docs: 引用聚合物文档:

By default, the filter and sort functions only run when the array itself is mutated (for example, by adding or removing items). 默认情况下,仅当数组本身发生突变(例如,通过添加或删除项目)时,才运行filter和sort函数。

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

Example: 例:

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

More info here: https://www.polymer-project.org/1.0/docs/devguide/templates.html#filtering-and-sorting-lists 此处提供更多信息: https : //www.polymer-project.org/1.0/docs/devguide/templates.html#filtering-and-sorting-lists

PS: you need to set your field using this.set("array.index.field", value), otherwise your observer won't be notified PS:您需要使用this.set(“ array.index.field”,value)设置字段,否则不会通知您的观察者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM