Ngrx 使我的分派对象只读

发布于 2025-01-16 21:46:11 字数 465 浏览 1 评论 0原文

我有以下代码行:

this.carInformation.subModel = [this.submodel.value]; 
this.store.dispatch(saveCriteria({ criteria: this.carInformation }));

当我的应用程序重新运行这两行时,我在第一行收到以下错误:

无法分配给对象“[object Object]”的只读属性“subModel”

为什么是 carInformation突然变成只读了?

我确实注意到使用以下代码行我的对象的可写属性现在为 false:

Object.getOwnPropertyDescriptor(this.carInformation, 'subModel');

我设法通过将调度移到其他地方来解决此问题,但我认为我可以重新编辑我的对象并重新调度它?

I've got the following lines of code:

this.carInformation.subModel = [this.submodel.value]; 
this.store.dispatch(saveCriteria({ criteria: this.carInformation }));

When my app re-runs these two lines, I get the following error on the first line:

Cannot assign to read only property 'subModel' of object '[object Object]'

Why is carInformation suddenly read only?

I did notice using the following line of code that the writable property of my object is now false:

Object.getOwnPropertyDescriptor(this.carInformation, 'subModel');

I managed to fix this by moving the dispatch elsewhere, but I would've figured that I could re-edit my object and re-dispatch it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-01-23 21:46:11

this.submodel.value 的引用被分派到存储。
因为存储具有不可变的运行时检查,所以该引用被“锁定”并在发生更改时抛出异常。

The reference of this.submodel.value is dispatched to the store.
Because the store has immutable runtime checks, that reference is "locked" and throws if it's changed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文