Replies: 12 comments 19 replies
-
|
一个简单直接的做法,amisgo 在 form 组件中定义一个 方法: func (f form) Go(action func(map[string]any)) form用户就可以这样写提交方法了: comp.Page().Body(
comp.Form().Body(
comp.InputText().Label("姓名").Name("name"),
comp.InputEmail().Label("邮箱").Name("email"),
).Go(func(m map[string]any) {
fmt.Println(m["name"])
fmt.Println(m["email"])
// save name and email to db
// ...
}),
) |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
看了amis的文档,好像还并不支持类似修改一个组件作为输入,经过一定转换得到输出渲染到另一个组件的交互。在 amis 提了 issue: |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
一个组件的输入经过转换渲染到另一个组件的方法也搞清楚了。 我在wiki写了目前为止所做的优化: 怎么简化交互代码 |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
原始交互描述
原始百度Amis中用json来描述交互,比如 form 组件中有个 api 字段:
{ "type": "page", "body": { "type": "form", "api": "/xxx", "body": [ { "type": "input-text", "name": "name", "label": "姓名:" }, { "name": "email", "type": "input-email", "label": "邮箱:" } ] } }当点击提交按钮后,会把name和email组合成json数据,post请求/xxx 这个 api。api可以是本进程(和amis前端相同的进程)的,也可以是其他地方的其他进程的。
简化诉求
以上json对应的 amisgo 代码是:
假设我们直接用当前进程来处理。需要在当前进程 serve 一个 xxx 的api才行。
有没有办法简化这个过程?
Beta Was this translation helpful? Give feedback.
All reactions