baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
17.33k stars 2.51k forks source link

俩个下拉框实现联动效果 #10466

Open coffin03 opened 4 months ago

coffin03 commented 4 months ago

实现场景:

使用编辑器操作面板在不修改源码的场景下,实现俩个下拉框接口联动效果

存在的问题:

在select1值变化回调中添加对select2的数据重新请求数据事件,在select2接口http配置中添加发送数据参数为select1,切换select值,select2重新请求了数据,但参数值拿到的是select1的旧值,并非当前值

当前方案:

image

image

image

2betop commented 4 months ago

表单项配置 strickMode: false

另外可以这个场景其实可以直接用这个机制 https://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/linkage#%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8

coffin03 commented 4 months ago

表单项配置 strickMode: false

另外可以这个场景其实可以直接用这个机制 https://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/linkage#%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8

{ "type": "form", "body": [ { "type": "select", "label": "选项1", "name": "select1", "options": [ { "label": "选项A", "value": "A" }, { "label": "选项B", "value": "B" } ], "id": "u:7fd35fab406e", "multiple": false, "onEvent": { "change": { "weight": 0, "actions": [ { "componentId": "u:3f3bf5be7036", "ignoreError": false, "actionType": "reload" } ] } }, "strictMode": false }, { "type": "select", "label": "选项2", "name": "select2", "id": "u:3f3bf5be7036", "multiple": false, "source": { "url": "http://dnn1a1cvipdt", "method": "post", "data": { "name": "${select1}" } }, "labelField": "name", "valueField": "id", "strictMode": false } ], "id": "u:68ad3b4c6589", "actions": [ { "type": "submit", "label": "提交", "primary": true, "id": "u:dc795c3d4eee" } ], "feat": "Insert" }

加了strictMode 没用

coffin03 commented 4 months ago

表单项配置 strickMode: false 另外可以这个场景其实可以直接用这个机制 https://aisuda.bce.baidu.com/amis/zh-CN/docs/concepts/linkage#%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8

{ "type": "form", "body": [ { "type": "select", "label": "选项1", "name": "select1", "options": [ { "label": "选项A", "value": "A" }, { "label": "选项B", "value": "B" } ], "id": "u:7fd35fab406e", "multiple": false, "onEvent": { "change": { "weight": 0, "actions": [ { "componentId": "u:3f3bf5be7036", "ignoreError": false, "actionType": "reload" } ] } }, "strictMode": false }, { "type": "select", "label": "选项2", "name": "select2", "id": "u:3f3bf5be7036", "multiple": false, "source": { "url": "http://dnn1a1cvipdt", "method": "post", "data": { "name": "${select1}" } }, "labelField": "name", "valueField": "id", "strictMode": false } ], "id": "u:68ad3b4c6589", "actions": [ { "type": "submit", "label": "提交", "primary": true, "id": "u:dc795c3d4eee" } ], "feat": "Insert" }

加了strictMode 没用

现在的应用场景是只使用编辑器的可视化面板进行配置 能不能用可视化面板在不更改源码的情况下实现这一需求

coffin03 commented 4 months ago

在chang 里加了 debounce防抖就可以拿到最新的值了