baidu / amis

前端低代码框架,通过 JSON 配置就能生成各种页面。
https://baidu.github.io/amis/
Apache License 2.0
17.1k stars 2.48k forks source link

输入框A不在表单里,输入框B和C在表单里,A等于B+C怎么实现? #10884

Open wanquantong opened 1 week ago

wanquantong commented 1 week ago

实现场景:

输入框A不在表单里 输入框B和C在表单里 A等于B+C 怎么实现?

试一:试了,$(B+C),不行。

试二:试了自定义公式,按钮点击,也不行

const var1 = "${ data.B }"; doAction({ actionType: 'toast', args: { msg: var1 } }); });`

lhtuling commented 1 week ago

外层包一个数据组件 比如service abc全部在data里面定义,然后就ok了

或者自定义事件里面 自己写js代码 怎么处理都可以

Amis低代码前端框架交流群【QQ 1群】:717791727 Amis低代码前端框架交流群【QQ 2群】:721182449

lhtuling commented 1 week ago

外层包一个数据组件 比如service abc全部在data里面定义,然后就ok了

或者自定义事件里面 自己写js代码 怎么处理都可以

Amis低代码前端框架交流群【QQ 1群】:717791727 Amis低代码前端框架交流群【QQ 2群】:721182449

抱歉 感觉不太对 测了下好像确实不行 那就换个方式 用表单的 值变化事件 然后用 组件赋值方法 给a组件赋值 b+c 就行了

{
  "type": "page",
  "body": [
    {
      "type": "input-text",
      "label": "a",
      "name": "a",
      "id": "u:77a06399e510"
    },
    {
      "id": "u:fd3bec100dfd",
      "type": "form",
      "title": "表单",
      "mode": "flex",
      "labelAlign": "top",
      "dsType": "api",
      "feat": "Insert",
      "body": [
        {
          "name": "b",
          "label": "b",
          "row": 0,
          "type": "input-text",
          "id": "u:2f238705938f"
        },
        {
          "name": "c",
          "label": "c",
          "row": 1,
          "type": "input-text",
          "id": "u:4fd592f354be"
        }
      ],
      "actions": [
        {
          "type": "button",
          "label": "提交",
          "onEvent": {
            "click": {
              "actions": [
                {
                  "actionType": "submit",
                  "componentId": "u:fd3bec100dfd"
                }
              ]
            }
          },
          "level": "primary",
          "id": "u:071b2238da04"
        }
      ],
      "resetAfterSubmit": true,
      "onEvent": {
        "change": {
          "weight": 0,
          "actions": [
            {
              "componentId": "u:77a06399e510",
              "ignoreError": false,
              "actionType": "setValue",
              "args": {
                "value": "${b+c}"
              }
            }
          ]
        }
      }
    }
  ],
  "id": "u:8bd27f3a3ab7",
  "asideResizor": false,
  "pullRefresh": {
    "disabled": true
  },
  "title": "增删改查示例",
  "remark": "bla bla bla",
  "regions": [
    "body"
  ]
}

Amis低代码前端框架交流群【QQ 1群】:717791727 Amis低代码前端框架交流群【QQ 2群】:721182449

wanquantong commented 1 week ago

外层包一个数据组件 比如service abc全部在data里面定义,然后就ok了 或者自定义事件里面 自己写js代码 怎么处理都可以 Amis低代码前端框架交流群【QQ 1群】:717791727 Amis低代码前端框架交流群【QQ 2群】:721182449

抱歉 感觉不太对 测了下好像确实不行 那就换个方式 用表单的 值变化事件 然后用 组件赋值方法 给a组件赋值 b+c 就行了

{
  "type": "page",
  "body": [
    {
      "type": "input-text",
      "label": "a",
      "name": "a",
      "id": "u:77a06399e510"
    },
    {
      "id": "u:fd3bec100dfd",
      "type": "form",
      "title": "表单",
      "mode": "flex",
      "labelAlign": "top",
      "dsType": "api",
      "feat": "Insert",
      "body": [
        {
          "name": "b",
          "label": "b",
          "row": 0,
          "type": "input-text",
          "id": "u:2f238705938f"
        },
        {
          "name": "c",
          "label": "c",
          "row": 1,
          "type": "input-text",
          "id": "u:4fd592f354be"
        }
      ],
      "actions": [
        {
          "type": "button",
          "label": "提交",
          "onEvent": {
            "click": {
              "actions": [
                {
                  "actionType": "submit",
                  "componentId": "u:fd3bec100dfd"
                }
              ]
            }
          },
          "level": "primary",
          "id": "u:071b2238da04"
        }
      ],
      "resetAfterSubmit": true,
      "onEvent": {
        "change": {
          "weight": 0,
          "actions": [
            {
              "componentId": "u:77a06399e510",
              "ignoreError": false,
              "actionType": "setValue",
              "args": {
                "value": "${b+c}"
              }
            }
          ]
        }
      }
    }
  ],
  "id": "u:8bd27f3a3ab7",
  "asideResizor": false,
  "pullRefresh": {
    "disabled": true
  },
  "title": "增删改查示例",
  "remark": "bla bla bla",
  "regions": [
    "body"
  ]
}

Amis低代码前端框架交流群【QQ 1群】:717791727 Amis低代码前端框架交流群【QQ 2群】:721182449

谢谢你的热心。其实我一个页面上,有多个表单,多个表单的输入框做统计,有没有办法?

lhtuling commented 1 week ago

谢谢你的热心。其实我一个页面上,有多个表单,多个表单的输入框做统计,有没有办法?

那就复杂点了,不过也可以的,你自己再琢磨琢磨看看 也可以看下我的b站的视频教程 https://space.bilibili.com/334359183 希望有启发