【发布时间】:2018-12-16 07:04:54
【问题描述】:
在 Aurelia 绑定中,如果在组件中我们对属性使用可观察装饰,并且如果属性是对象,那么我们将订阅该对象的所有属性。
例如:
import { observable } from 'aurelia-framework';
export class Car {
@observable color = {rgb: '', hex: ''};
colorChanged(newValue, oldValue) {
// this will fire whenever the 'color' property changes
}
}
因此,如果其中一个颜色属性发生变化,那么它将触发 colorChanged。但在自定义元素中,我们有这样的可绑定对象:
import {bindable, bindingMode} from 'aurelia-framework';
export class SecretMessageCustomElement {
@bindable data;
dataChanged () {
// -------
}
}
那么 dataChanged 将不会在其属性更改时被调用。怎么解决?
【问题讨论】:
-
我已经写了一个通用的解决方案,很快就会回答我的问题。
标签: observable aurelia bindable