且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-02 13:05:28

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

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.org/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