amis
amis copied to clipboard
input-table中使用combo组合表单项时数据回传出错
描述问题:
当在input-table
中使用combo
组合表单项时,里面有有一个输入框和一个下拉框,更改下拉框的值会导致输入框的值为空,更改输入框的值会导致下拉框的值为空,个人推测是数据变化时向上传递的出错导致,具体原因还请大佬给查一下
截图或视频:
如何复现(请务必完整填写下面内容):
-
你是如何使用 amis 的?
sdk
-
amis 版本是什么?请先在最新 beta 版本测试问题是否存在 version:1.9.0
-
粘贴有问题的完整
amis schema
代码:
{
"type": "form",
"title": "表单",
"body": [
{
"type": "input-table",
"id": "u:44743c661b99",
"name": "table-01",
"label": "表格表单",
"columns": [
{
"type": "checkbox",
"label": "选择字段",
"name": "isAsync",
"placeholder": "-",
"remark": "选择后CDP才会同步"
},
{
"label": "字段",
"name": "field_name",
"type": "static"
},
{
"label": "字段类型",
"name": "field_type",
"type": "static"
},
{
"type": "static",
"label": "实体ID字段",
"name": "entity_id"
},
{
"type": "input-text",
"label": "字段说明",
"name": "desc"
},
{
"type": "combo",
"label": "是否字典",
"name": "dict",
"multiple": false,
"items": [
{
"type": "select",
"name": "isDict",
"placeholder": "选项",
"options": [
{
"label": "是",
"value": true
},
{
"label": "否",
"value": false
}
]
},
{
"type": "input-text",
"visibleOn": "",
"name": "dict_name"
},
{
"type": "button",
"label": "添加字典表",
"actionType": "",
"dialog": {
"title": "系统提示",
"body": "对你点击了"
},
"id": "u:5bbe215626bd",
"visibleOn": "!!this.isDict",
"level": "primary"
}
],
"multiLine": false,
"joinValues": false,
"messages": {
},
"canAccessSuperData": false,
"strictMode": true,
"syncFields": ""
},
{
"type": "select",
"label": "是否允许为空",
"name": "isEmpty",
"checkAll": false,
"options": [
{
"label": "是",
"value": true
},
{
"label": "否",
"value": false
}
],
"className": "border-l border-gray-300 ",
"style": {
"border-left-style": "solid"
}
}
],
"strictMode": true,
"columnsTogglable": false,
"required": true,
"mode": "horizontal"
},
{
"type": "static",
"label": "描述",
"id": "u:0766831caeff"
},
{
"type": "combo",
"label": "组合输入",
"id": "u:928b2e53d1f5",
"name": "combo",
"multiple": false,
"items": [
{
"type": "input-text",
"name": "aaa",
"placeholder": "选项",
"options": [
{
"label": "A",
"value": "a"
},
{
"label": "B",
"value": "b"
}
]
},
{
"type": "button",
"label": "按钮",
"actionType": "dialog",
"dialog": {
"title": "系统提示",
"body": "对你点击了"
},
"id": "u:5bbe215626bd"
}
],
"multiLine": false,
"joinValues": false,
"messages": {
}
},
{
"type": "input-group",
"label": "input 组合",
"name": "input-group",
"id": "u:ec30a6394314",
"body": [
{
"type": "select",
"inputClassName": "b-r-none p-r-none w-full",
"name": "input-group"
},
{
"type": "submit",
"label": "提交",
"level": "primary"
}
]
}
],
"mode": "horizontal",
"id": "u:9a82dcf94464",
"data": {
"table-01": [
{
"field_name": "@$7[Pq",
"field_type": "Z@*Ko!",
"entity_id": "HCJ^5h",
"isEmpty": false,
"dict": {
"isDict": true,
"dict_name": "aa"
},
"isAsync": false
},
{
"field_name": "Yy1",
"field_type": "AckJz",
"entity_id": "*hD",
"isEmpty": true,
"dict": {
"isDict": false,
"dict_name": "aa"
},
"isAsync": true
},
{
"field_name": "KUCd",
"field_type": "N)*D",
"entity_id": "9XT61#",
"isEmpty": false,
"dict": {
"isDict": true,
"dict_name": "aa"
},
"isAsync": true
}
]
},
"api": "http://demo01.com"
}
- 操作步骤 请简单描述一下复现的操作步骤...
👍 Thanks for this! 🏷 I have applied any labels matching special text in your issue.
Please review the labels and make any necessary changes.
将查看源码,在packages/amis/src/renderers/Form/InputTable.tsx#L1023
的1023行,如下:
const origin = getTree(items, indexes);
const data = {
...origin,
...diff
};
这里,如果diff
里面存在字段的值是对象,比如combo组件是对象的时候(如:a: {age: 18, name: 'jack'}) 中,name发生了变化,由'jack'变成了'tom',则diff
变成了a:{name: 'tom'}
,这种情况下上面的orgin
里面的a
会被diff
里面的a覆盖掉,因此,这里我觉得应该是const data = {...orign, ...rows}
,这样数据才对
@2betop @nwind @lghxuelang
@lurunze1226 辛苦看下这个有木有最优解 麻烦修复一下 谢谢!
@2betop @lurunze1226 这里还有个问题哈,麻烦看一下,辛苦!