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