select组件人员点选与form组件api结合使用时,select组件内source api接口中拿不到form表单中的字段值
- Dominant language
- TypeScript
- Stars
- 18.9k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
#### 描述问题:
如题,这个问题造成无法按官网示例中的select组件“人员点选”功能实现form组件中编辑记录时人员字段初始值显示。
#### 截图或视频:

#### 如何复现(请务必完整填写下面内容):
1. 你是如何使用 amis 的?
sdk
2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在
2.5.2,2.6.0,2.6.1-alpha.0,我们在实际项目中试过这些版本都有问题。
4. 粘贴有问题的完整 `amis schema` 代码:
以下amis schema来自官网示例 https://aisuda.bce.baidu.com/amis/zh-CN/components/form/select#%E4%BA%BA%E5%91%98%E7%82%B9%E9%80%89 修改后的代码。
```
{
"type": "page",
"body": {
"type": "form",
"debug": true,
"initApi": {
"url": "/amis/api/mock2/form/saveForm",
"adaptor": "payload.data={a:'3',b:'user1'};return payload;"
},
"data": {
"b3": "user1"
},
"body": [
{
"label": "人员选择",
"type": "select",
"name": "b",
"multiple": true,
"sortable": true,
"searchable": true,
"selectMode": "associated",
"leftMode": "tree",
"source": {
"data": {
"x": "x",
"&": "$$"
},
"url": "/amis/api/mock2/form/departUser",
"requestAdaptor": "console.log('====requestAdaptor==api=', api);return api;",
"adaptor": "payload.data={'options':[{'defaultValueOptions':[{'label':'用户 1','value':'user1'},{'label':'用户 2','value':'user2'}],'leftOptions':[{'label':'总公司','value':1,'defer':true}],'children':[{'ref':1,'defer':true},{'ref':2,'defer':true},{'ref':3,'defer':true},{'ref':4,'defer':true},{'ref':5,'defer':true},{'ref':6,'defer':true}]}]};return payload;"
},
"sourcexx": "/amis/api/mock2/form/departUser",
"searchApi": "/amis/api/mock2/form/departUserSearch?term=${term}",
"deferApi": "/amis/api/mock2/form/departUser?ref=${ref}&dep=${value}"
},
{
"label": "A",
"type": "input-text",
"name": "a"
}
]
}
}
```
6. 操作步骤
##### 实际需求场景
点击按钮弹出记录编辑窗口,form中人员字段未能显示label,而是显示了字段值,即人员id。
##### 上述代码场景
复制上述amis schema代码,打开官网示例 https://aisuda.bce.baidu.com/amis/zh-CN/components/form/select#%E4%BA%BA%E5%91%98%E7%82%B9%E9%80%89 ,粘贴到该示例的amis schema中完整替换原代码。
我们会发现浏览器控制台会输出人员字段source接口requestAdaptor函数中的"==requestAdaptor==api="日志,可以看到日志中并没有不能取到form initApi接口返回值,而source api发送适配器中的人员字段id值(来自form的initApi返回值)如果拿不到的话,就无法根据id值在服务端算出defaultValueOptions,也就无法实现在form表单中的人员字段显示为人员名称而不是人员字段id的功能。
进一步,我们把source api接口的url改为"/amis/api/mock2/form/departUser?a=${a}",即在后面带上动态参数,这样的话,我们会看到source接口请求了两次,第一次虽然没拿到form表单接口返回的字段值,但是第二次是能拿到完整的字段值的。问题是加参数让人员字段source接口请求两次的方案在部分情况下并不会生效,实际应用场景中我们遇到加参数后只请求一次的情况,只请求一次的话是不能在source api接口的发送适配器函数中拿到表单initApi接口返回的字段值的。

Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the official Select component “人员点选” example and reproduce the provided schema using the form initApi and the select source requestAdaptor. Trace when the form’s initialized field value becomes available to the source API, including the single-request and dynamic-parameter cases. Done means the source requestAdaptor can consistently access the initialized value and the edit form displays the user label instead of its ID.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100