amis icon indicating copy to clipboard operation
amis copied to clipboard

使用 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.

Open yanquer opened this issue 1 year ago • 1 comments

关键 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 avatar Oct 17 '24 08:10 yanquer

暂时实验后可以通过 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"},
                                                                ],
                                                            },
                                                        ],
                                                    },
                                                ]},

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

yanquer avatar Oct 17 '24 08:10 yanquer

后面解决了吗?我用编辑器,拖拉拽组件的时候就报这个错(vue3+amis-editor)

Image

zhangjiayu139 avatar Mar 21 '25 10:03 zhangjiayu139

后面解决了吗?我用编辑器,拖拉拽组件的时候就报这个错(vue3+amis-editor)

Image

看上一条回复, 我是用表单 form 包了一层

yanquer avatar Mar 24 '25 01:03 yanquer