amis icon indicating copy to clipboard operation
amis copied to clipboard

表单提交以后,如何把返回信息呈现在页面固定区域

Open tanmengfei opened this issue 6 years ago • 10 comments

类似于postman的response那里

tanmengfei avatar May 15 '20 08:05 tanmengfei

可以表单中配置一个json-editor,name与你接口返回的值进行同名映射,应该就能显示了

RickCole21 avatar May 19 '20 08:05 RickCole21

可以表单中配置一个json-editor,name与你接口返回的值进行同名映射,应该就能显示了 假如返回结果是这个{"status":0,"msg":"保存成功","data":{"id":1}},然后我想把这个显示在json-editor中,那么json-editor的name值该怎么设置呢

tanmengfei avatar May 19 '20 08:05 tanmengfei

这样的话应该需要在接口写adaptor,大概如下:

 "api": {
        "method": "post",
        "url": "/api/mock2/form/saveForm",
        "adaptor": "return {\n    ...payload,\n    data: {\n        ...payload.data,\n        response: response.data\n    }\n}"
    },

adaptor内容是:

return {
    ...payload,
    data: {
        ...payload.data,
        response: response.data
    }
}

逻辑就是把adaptor函数签名中的response数据,加入到data中,这样你的editor的name设置为response就能映射了

adaptor这里也可以直接配一个function,如果你的使用方法可以配function的话

RickCole21 avatar May 19 '20 08:05 RickCole21

太谢谢啦!现在在form表单里边可以获取返回结果了,有办法在form表单外获取嘛

tanmengfei avatar May 19 '20 09:05 tanmengfei

可以,给form配置"reload": "xxx?response=${response}",xxx是另外一个组件的name属性值。

response=${response}可以把当前数据域中的response值传给xxx组件,xxx组件内就可以使用这个数据了

你可能需要看下高级用法

RickCole21 avatar May 19 '20 09:05 RickCole21

我天,成功啦,太谢谢啦,我知道这种用法,但是没想到==,还是使用不太熟练

tanmengfei avatar May 19 '20 09:05 tanmengfei

star 支持一下?😎

RickCole21 avatar May 19 '20 09:05 RickCole21

已支持,哈哈

tanmengfei avatar May 19 '20 09:05 tanmengfei

能贴一个完整,可运行的示例吗?

i323654 avatar May 21 '20 03:05 i323654

我按上面的配置写,api 还没返回的时候 json 就已经渲染了 不是想要的结果 这个怎么办

Caeser-SONG avatar Aug 04 '23 10:08 Caeser-SONG