amis icon indicating copy to clipboard operation
amis copied to clipboard

想要给表单确定按钮绑定一个自定义点击方法

Open x1194785386 opened this issue 6 years ago • 17 comments

删除1 删除2 新增

x1194785386 avatar Dec 17 '19 02:12 x1194785386

点击后做什么操作?好奇,截图貌似还是老版本。

2betop avatar Dec 17 '19 02:12 2betop

是想让确定按钮去执行一个自己的后端接口调用方法

x1194785386 avatar Dec 17 '19 03:12 x1194785386

actionType 配置成 'ajax', 然后配置 api 属性就够了。这里面有很多种按钮类型。

https://baidu.github.io/amis/docs/renderers/Action

2betop avatar Dec 17 '19 03:12 2betop

是这样的,我是有一套后端接口调用函数,是想用这个确认按钮去调用。

x1194785386 avatar Dec 17 '19 03:12 x1194785386

确认按钮就是配置个 actionType 为 'ajax' 类型的按钮,然后配置 api, 再配置个 confirmText 就完了。

点击的时候自动会弹出个确认框,确认完了就会走 ajax 操作。

2betop avatar Dec 17 '19 03:12 2betop

跟这个栗子的用法时一样的。https://baidu.github.io/amis/crud/table?page=1

ps:左上角可以查看源码。

2betop avatar Dec 17 '19 03:12 2betop

那是没办法,给确认按钮配置可以去调用函数吗?

x1194785386 avatar Dec 17 '19 03:12 x1194785386

作者大大这个我是知道的,只不过需求是要用确认按钮去调用函数。

x1194785386 avatar Dec 17 '19 03:12 x1194785386

调用后端的函数都是走 api,你的意思是前端的函数?

2betop avatar Dec 17 '19 03:12 2betop

是的前端函数

x1194785386 avatar Dec 17 '19 03:12 x1194785386

如果你是用 js 来配置 amis,可以这么弄。

{
   type: "button"
   label: "删除",
  actionType: "dialog",
  dialog: {
      title: "系统消息",
      body: "确认要删除?",
      actions: [
          {
             type: "button",
             label: "确认",
             actionType: "close"
             onClick: () => {
                   alert('clicked');
                   // return false 可以阻止 amis 里面后续的动作。
             }
          },
          {
              label: "取消",
              type: "button",
              actionType: "close"
          }
      ]
  }
}

2betop avatar Dec 17 '19 03:12 2betop

作者大大,我在onClik写了一个函数,它并不加载该函数,甚至actionType以下都不执行。

代码1

弹框1

x1194785386 avatar Dec 17 '19 07:12 x1194785386

最外层的 onClick 进去没?

2betop avatar Dec 17 '19 09:12 2betop

在props.onAction前面的都执行了

---原始邮件--- 发件人: "liaoxuezhi"<[email protected]> 发送时间: 2019年12月17日(周二) 下午5:28 收件人: "baidu/amis"<[email protected]>; 抄送: "Author"<[email protected]>;"x1194785386"<[email protected]>; 主题: Re: [baidu/amis] 想要给表单确定按钮绑定一个自定义点击方法 (#380)

最外层的 onClick 进去没?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

x1194785386 avatar Dec 17 '19 09:12 x1194785386

看这像是进入了第二个分支。你看看 第二个 onAction 那块

2betop avatar Dec 17 '19 09:12 2betop

好的我先理理

---原始邮件--- 发件人: "liaoxuezhi"<[email protected]> 发送时间: 2019年12月17日(周二) 下午5:47 收件人: "baidu/amis"<[email protected]>; 抄送: "Author"<[email protected]>;"x1194785386"<[email protected]>; 主题: Re: [baidu/amis] 想要给表单确定按钮绑定一个自定义点击方法 (#380)

那就没问题了,你下面一看就好乱,自己先理一理。

不知道你 viewJson 是啥

用了 map,但是 方法没有返回。

actionName 是啥?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

x1194785386 avatar Dec 17 '19 09:12 x1194785386

作者大大我这边代码少了一层return false;,已经解决了,麻烦您了。

x1194785386 avatar Dec 18 '19 01:12 x1194785386