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

霸气de小男生 提交于 2020-01-25 18:25:30

问题


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>

回答1:


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).

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.

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

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



来源:https://stackoverflow.com/questions/33627446/how-to-re-run-dom-repeat-with-sort-when-bool-property-changed-in-polymer-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!