如何刷新过滤的aurelia repeat.for binding

时间:2017-09-20 18:20:38

标签: aurelia aurelia-binding

给定一个具有绑定到视图中多个列表的项列表的类,在修改元素时刷新视图的推荐方法是什么?

我是否删除旧项目并添加新项目,举办活动或其他内容?

export class Model {
  items: Item[];
  filter1 = x => x.isActive;
  filter2 = x => x.Value > 5;

  modifyItem(item) {
    item.isActive = true;
    item.Value = 22;
  }
}


<template repeat.for="item of items | filter:filter1">...</template>
<template repeat.for="item of items | filter:filter2">...</template>

1 个答案:

答案 0 :(得分:3)

您可以使用signal binding behavior通知它某些内容已发生变化,并且需要刷新过滤器:

<template repeat.for="item of items | filter:filter1 & signal:'item-modified'">...</template>

在你的组件中:

import {BindingSignaler} from 'aurelia-templating-resources';
import {autoinject} from 'aurelia-framework';

@autoinject()
export class Model {
  items: Item[];
  filter1 = x => x.isActive;
  filter2 = x => x.Value > 5;

  constructor(private signaler: BindingSignaler) { }

  modifyItem(item) {
    item.isActive = true;
    item.Value = 22;
    signaler.signal('item-modified');
  }
}