问题
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