amis icon indicating copy to clipboard operation
amis copied to clipboard

使用service初始化 “引用表单“中的数据时的问题

Open XiuPunica opened this issue 6 years ago • 4 comments

问题描述

  1. form中使用service来控制表单,没有问题;

  2. 使用 “引用表单”来编写页面信息提交,没有问题;

  3. 使用service来给 “引用表单” 进行值的初始化时,遇到了问题。表现为:

    1. 当下拉列表a获取到source,且未操作时,service会顺序请求所有下拉列表a的结果

代码部分:


    "controls": [
                {
                    "name": "a",
                    "type": "select",
                    "label": "下拉列表",
                    "source": "http://localhost:8552/exview/xxx",
                    "description": "请选择对应的jira项目"
                },
                {
                    "type": "divider"
                },
                {
                    "type": "service",
                    "api": "http://localhost:8552/exview/xxbb?select_a=${a}&sub_type=update_page",
                    "controls": [
                        {
                            "$ref": "release_info_option",
                            "name": "release_info",
                            "value": "${release_info}",
                            "addButtonText": "增加内容"
                        },
                        {
                            "type": "static",
                            "name": "q",
                            "label": "当前值",
                            "tpl": "<pre>${a}</pre><pre>${release_info|json}</pre>"
                        }
                    ]
                }

这种场景下该如何使用呢?求解

XiuPunica avatar Jan 07 '20 09:01 XiuPunica

你的意思是,service 请求早了把。

service 的 api 配置成这样?

{
                    "type": "service",
                    "api": {
  "url": "http://localhost:8552/exview/xxbb?select_a=${a}&sub_type=update_page",
  "method": "get",
  "sendOn": "this.a"
},
                    "controls": [
                        {
                            "$ref": "release_info_option",
                            "name": "release_info",
                            "value": "${release_info}",
                            "addButtonText": "增加内容"
                        },
                        {
                            "type": "static",
                            "name": "q",
                            "label": "当前值",
                            "tpl": "<pre>${a}</pre><pre>${release_info|json}</pre>"
                        }
                    ]
                }

2betop avatar Jan 07 '20 09:01 2betop

嗯,感谢! 这种方式果然可以。 那这个问题的原因是啥呢? service中不使用引用的话,api直接可以用 ${a};如果使用引用的话,就需要显式的指定"sendOn": "this.a"

XiuPunica avatar Jan 07 '20 09:01 XiuPunica

原因,service 第一请求的时候并没有数据 a,所以给它配置了个发送条件。

至于为什么后面service 又请求,是因为 url 的结果发生变化,又会自动再走一次请求逻辑。这是 amis 内部的设定。

2betop avatar Jan 07 '20 09:01 2betop

好的。了解了。多谢~

XiuPunica avatar Jan 07 '20 09:01 XiuPunica