Aurelia-computedFrom装饰程序引用的嵌套数组没有ModifyCollectionObserver?
让我们假设我的类是这样的:Aurelia-computedFrom装饰程序引用的嵌套数组没有ModifyCollectionObserver?,aurelia,Aurelia,让我们假设我的类是这样的: import { computedFrom } from 'aurelia-framework'; export class Test { myObj; @computedFrom('myObj.myArray') get someProperty() { debugger; return JSON.stringify(this.myObj ? this.myObj.myArray : this.myObj
import { computedFrom } from 'aurelia-framework';
export class Test {
myObj;
@computedFrom('myObj.myArray')
get someProperty() {
debugger;
return JSON.stringify(this.myObj ? this.myObj.myArray : this.myObj);
}
attached() {
this.myObj = {
myArray: []
};
setTimeout(() => this.myObj.myArray.push('foo'), 500);
}
}
我的HTML只是:
<template>
<h3>myArray value: ${someProperty}</h3>
</template>
myArray值:${someProperty}
我遇到了一个问题,someProperty
在我将元素推入myObj.myArray
时没有被更新。我用someProperty
getter中的调试器验证了这一点。当this.myObj
最初在attached
中设置并且随后调用someProperty
getter时,我看到myObj
是this中的SetterObserver
但是,我在this.myObj.\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。我希望阵列上会有某种观测者,因为它在我的computedFrom
装饰器中被指定为依赖项。您可以将computedFrom
装饰器更改为以下内容,然后事情将开始工作:
@computedFrom('myObj.myArray.length')
这是因为当您将项目推入数组时,length
属性将发生变化,Aurelia可以观察到这种变化。computedFrom('myObj.myArray.length')
有效吗?@AshleyGrant有效,谢谢!如果你不回答这个问题,我会接受的。然而,我希望有一种不那么黑客的方式来做这件事。是的,没有使用代理,很不幸,我知道没有一种不那么黑客的方式。