Giter Site home page Giter Site logo

Comments (3)

github-actions avatar github-actions commented on May 3, 2024

👍 Thanks for this!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

from amis.

CheshireJCat avatar CheshireJCat commented on May 3, 2024

要实现这个有以下几个要点:
1.先说说你的使用误区,为了避免死循环,组件不能对自己执行动作,所以在add事件中执行不会生效
2. 所以如果要生效,需要去掉combo原来的新增按钮,设置 addable 为 false
3. 在下面新增一个模拟按钮新增按钮,然后这个按钮点击的时候,对combo执行新增动作addItem
4. 设置新增的值,需要用到很多表达式(具体可以查看文档)以此来计算新的值
5. 另外,这种计算值比较复杂的操作用自定义动作写js获取比较方便,可以尝试一下

完整的schema如下,应该是你要的效果:

{
  "type": "form",
  "id": "u:1bd293cd8bba",
  "title": "表单",
  "debug": true,
  "body": [
    {
      "type": "combo",
      "id": "u:6668b5cd6246",
      "name": "combo11",
      "label": "组合多条多行内联",
      "multiple": true,
      "multiLine": false,
      "inline": true,
      "value": [
        {
          "start": "00:00",
          "end": "01:00",
          "price_category": 0
        }
      ],
      "addable": false,
      "items": [
        {
          "type": "input-time-range",
          "label": "时间范围",
          "name": "start",
          "id": "u:5c130c3d188f",
          "displayFormat": "HH:mm",
          "placeholder": "请选择时间范围",
          "valueFormat": "HH:mm",
          "minDate": "",
          "shortcuts": [],
          "extraName": "end",
          "endPlaceholder": "结束时间",
          "autoFill": {},
          "required": true,
          "embed": false,
          "unique": true,
          "value": "",
          "maxDate": ""
        },
        {
          "type": "select",
          "label": "价格类别",
          "name": "price_category",
          "options": [
            {
              "label": "尖费率",
              "value": 0
            },
            {
              "label": "峰费率",
              "value": 1
            },
            {
              "label": "平费率",
              "value": 2
            },
            {
              "label": "谷费率",
              "value": 3
            }
          ],
          "id": "u:c800ea06ec55",
          "multiple": false,
          "required": true,
          "value": ""
        }
      ],
      "strictMode": true,
      "maxLength": 24,
      "minLength": 1,
      "removableMode": "button",
      "removable": true,
      "canAccessSuperData": false,
      "draggable": false,
      "tabsMode": false,
      "size": "full",
      "syncFields": [],
      "lazyLoad": false,
      "className": "mb-1"
    },
    {
      "type": "button-toolbar",
      "label": "",
      "buttons": [
        {
          "type": "button",
          "label": "新增",
          "icon": "fa fa-plus",
          "level": "primary",
          "size": "sm",
          "onEvent": {
            "click": {
              "weight": 0,
              "actions": [
                {
                  "componentId": "u:6668b5cd6246",
                  "ignoreError": false,
                  "actionType": "addItem",
                  "args": {
                    "item": {
                      "start": "${combo11[COUNT(combo11)-1].end}",
                      "end": "${DATETOSTR(DATEMODIFY(STRTODATE('2000/01/01 '+combo11[COUNT(combo11)-1].end+ ':00'), 1, 'hours'), 'HH:mm')}",
                      "price_category": "${HOUR(STRTODATE('2000/01/01 '+combo11[COUNT(combo11)-1].end+ ':00')) % 2}"
                    }
                  }
                }
              ]
            }
          }
        }
      ]
    }
  ]
}

from amis.

CheshireJCat avatar CheshireJCat commented on May 3, 2024

另外,我看你另一个issue #9415 也是为了解决一样的问题吧

from amis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.