当Polymer元素中的bool属性更改时如何使用排序重新运行dom-repeat [英] How to re run dom-repeat with sort when bool property changed in Polymer element

查看:88
本文介绍了当Polymer元素中的bool属性更改时如何使用排序重新运行dom-repeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于当Polymer元素中的bool属性更改时如何使用排序重新运行dom-repeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆