Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用 dialog 给外部表单设置数据时候, 数组设置空数据时会遇到报错 [mobx-state-tree] You are trying to read or write to an object that is no longer part of a state tree. (Object type: 'FormStore', Path upon death: '', Subpath: '', Action: '.setCurrentAction()'). Either detach nodes first, or don't use objects after removing / replacing them in the tree. #11070

Open
yanquer opened this issue Oct 17, 2024 · 1 comment

Comments

@yanquer
Copy link

yanquer commented Oct 17, 2024

关键 Json

{
            "type": "service",
            "id": "testTableId2",
            "name": "testTableId2",
            "data": {
                "tDItems": [
                    {
                        "name": "bob",
                        "age": 20,
                        "addr": "大中华",
                    },
                    {
                        "name": "bob2",
                        "age": 200,
                        "addr": "大中华2",
                    },
                ],
            },
            "body": [
                {
                    "type": "service",
                    "name": "tablePage2",
                    "body": [
                        {
                            "type": "table",
                            "name": "table_test2",
                            "source": "$tDItems",
                            "affixHeader": false,
                            "syncLocation": false,
                            "columns": [
                                {
                                    "name": "name",
                                    "label": "name",
                                    "type": "text"
                                },
                                {
                                    "name": "age",
                                    "label": "age",
                                    "type": "text"
                                },
                                {
                                    "type": "text",
                                    "label": "addr",
                                    "name": "addr"
                                },
                            ],
                        },
                    ]
                },
                {
                    "type": "button",
                    "label": "Edit",
                    "level": "primary",
                    "onEvent": {
                        "click": {
                            "actions": [
                                {
                                    "actionType": "dialog",
                                    "dialog": {
                                        "type": "dialog",
                                        "body": [
                                            {"type": "input-array", "name": "tDItems", "label": "tDItems",
                                                "items": [
                                                    {"type": "combo", "controls": [
                                                            {"label": "name", "name": "name", "type": "input-text"},
                                                            {"label": "age", "name": "age", "type": "input-text"},
                                                            {"label": "addr", "name": "addr", "type": "input-text"},
                                                        ],
                                                    },
                                                ],
                                            },
                                        ],
                                        "onEvent": {
                                            "confirm": {
                                                "actions": [
                                                    {"actionType": "setValue", "componentName": "testTableId2",
                                                        "args": {"value": {"tDItems": "$tDItems"},},
                                                    },
                                                ],
                                            },
                                        },
                                    }
                                }
                            ]
                        }
                    }
                }
            ]
        }

外部表格渲染的数据会同时显示在 dialog 第一次打开时.

但, 当打开 dialog, 并清空数组, 点击 确认 按钮, 会遇到报错

[mobx-state-tree] You are trying to read or write to an object that is no longer part of a state tree. (Object type: 'FormStore', Path upon death: '', Subpath: '', Action: '.setCurrentAction()'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.

点击确定时候报错

不过外部数据可以正常清空.

@yanquer
Copy link
Author

yanquer commented Oct 17, 2024

暂时实验后可以通过 form 表单包裹一下解决.
dialog 的 body 内容设置为

{"type": "form", "body": [
                                                    {"type": "input-array", "name": "tDItems", "label": "tDItems",
                                                        "items": [
                                                            {"type": "combo", "controls": [
                                                                    {"label": "name", "name": "name", "type": "input-text"},
                                                                    {"label": "age", "name": "age", "type": "input-text"},
                                                                    {"label": "addr", "name": "addr", "type": "input-text"},
                                                                ],
                                                            },
                                                        ],
                                                    },
                                                ]},

就是样式可能需要再额外自行调整一下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant