Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

级联 select,如何设置当第一个select变化时触发清空第二个select的值,valueTemplate好像没有效果 #188

Open
leo0o opened this issue Nov 11, 2020 · 4 comments

Comments

@leo0o
Copy link

leo0o commented Nov 11, 2020

作者你好,我想要当第一个下拉框发生变化时,第二个框能自动清空内容,但是现在情况是,只有在第二个框刚加载出来的时候,值会被初始化,其他时候第二个框就不会再跟随变化了,请问是我设置的有问题吗,代码如下:

{
  "type": "object",
  "properties": {
    "data": {
      "type": "array",
      "ui": {
        "widget": "array-table",
        "widgetConfig": {},
        "columns": 12,
        "showLabel": true,
        "noLabelSpace": false,
        "showLegend": false,
        "disabled": false,
        "readonly": false,
        "hidden": false,
        "help": {
          "show": false,
          "text": "?"
        },
        "linkFields": []
      },
      "rules": {},
      "items": {
        "type": "object",
        "items": {},
        "properties": {
          "type": {
            "type": "string",
            "ui": {
              "widget": "select",
              "widgetConfig": {
                "enumSource": [
                  {
                    "label": "A",
                    "value": "A"
                  },
                  {
                    "label": "B",
                    "value": "B"
                  }
                ]
              },
              "columns": 12,
              "showLabel": true,
              "noLabelSpace": false,
              "showLegend": false,
              "disabled": false,
              "readonly": false,
              "hidden": false,
              "help": {
                "show": false,
                "text": "?"
              },
              "linkFields": []
            },
            "rules": {}
          },
          "subtype": {
            "type": "string",
            "ui": {
              "widget": "select",
              "widgetConfig": {
                "enumSource": "dx: {{$const}}[{{$root.data[i].type}}]"
              },
              "columns": 12,
              "showLabel": true,
              "noLabelSpace": false,
              "showLegend": false,
              "disabled": false,
              "readonly": false,
              "hidden": false,
              "help": {
                "show": false,
                "text": "?"
              },
              "linkFields": []
            },
            "rules": {
              "customRule": []
            },
            "valueTemplate": "0",
            "base": {
              "key": "subtype",
              "type": "string",
              "valueTemplate": "0"
            }
          }
        }
      },
      "base": {
        "key": "data",
        "type": "array",
        "items": {
          "type": "object",
          "items": {},
          "properties": [
            {
              "type": "string",
              "ui": {
                "widget": "select",
                "widgetConfig": {
                  "enumSource": [
                    {
                      "label": "A",
                      "value": "A"
                    },
                    {
                      "label": "B",
                      "value": "B"
                    }
                  ]
                },
                "columns": 12,
                "showLabel": true,
                "noLabelSpace": false,
                "showLegend": false,
                "disabled": false,
                "readonly": false,
                "hidden": false,
                "help": {
                  "show": false,
                  "text": "?"
                },
                "linkFields": []
              },
              "rules": {},
              "key": "type"
            },
            {
              "type": "string",
              "ui": {
                "widget": "select",
                "widgetConfig": {
                  "enumSource": "dx: {{$const}}[{{$root.data[i].type}}]"
                },
                "columns": 12,
                "showLabel": true,
                "noLabelSpace": false,
                "showLegend": false,
                "disabled": false,
                "readonly": false,
                "hidden": false,
                "help": {
                  "show": false,
                  "text": "?"
                },
                "linkFields": []
              },
              "rules": {
                "customRule": []
              },
              "valueTemplate": "0",
              "base": {
                "key": "subtype",
                "type": "string",
                "valueTemplate": "0"
              },
              "key": "subtype"
            }
          ]
        }
      }
    }
  },
  "root": true,
  "globalConfig": {
    "ignoreRulesWhenHidden": true,
    "style": {},
    "css": {},
    "constants": {
      "A": [
        {
          "label": "a1",
          "value": "a1"
        },
        {
          "label": "a2",
          "value": "a2"
        }
      ],
      "B": [
        {
          "label": "b1",
          "value": "b1"
        },
        {
          "label": "b2",
          "value": "b2"
        }
      ]
    },
    "scrollToFailField": {
      "enabled": false
    }
  },
  "checked": false,
  "ui": {
    "widgetConfig": {}
  }
}
@daniel-dx
Copy link
Collaborator

最近比较忙,问题跟进得比较慢,见谅哈

你的问题可以通过尝试这个设置 selectFirstItem: false

{
  multiple: false, // Whether to choose more
  clearable: true, // Whether the empty button appears
  filterable: false, // Whether searchable
  filterLocal: true, // Filter by local or remote data. if true, even with enumSourceRemote, data will only be retrieved once remotely.
  size: '', // Size. Options:[medium | small | mini]

  itemDataKey: "", // The key of the selected item's data, can accessed by {{$temp[itemDataKey]}}

  itemTemplate: '<span>{{item.label}} : {{item.value}}</span>', // Display item template
  itemLabelField: 'label', // Item data represents the field of the label
  itemValueField: 'value', // Item data represents the field of value
  enumSource: [{value: [String | Number | Boolean], label: ''}], // Local data source
  enumSourceRemote: { // Remote data source
    remoteUrl: '', // If it is remote call, fill in the url
    paramName: 'keyword', // Request parameter name, default is keyword
    otherParams: {}, // Additional request parameters.
    resField: '', // Response result field
    selectFirstItem: false // Whether the first item is selected by default
  },
}

@leo0o
Copy link
Author

leo0o commented Nov 30, 2020

作者你好,由于这个数据读取的是全局 $const 里面的,设置 selectFirstItem 可能没用,试过确实没效果。

@luqiudi
Copy link

luqiudi commented Jul 23, 2021

作者你好,由于这个数据读取的是全局 $const 里面的,设置 selectFirstItem 可能没用,试过确实没效果。

你好,我想问下,你这个用dx表达式写在enumSource属性里面形成前后级联的这种形式行得通么

@luqiudi
Copy link

luqiudi commented Jul 29, 2021

作者你好,由于这个数据读取的是全局 $const 里面的,设置 selectFirstItem 可能没用,试过确实没效果。

你可以试试在valuetemplate后边跟一个函数来处理一下清空这个逻辑
我现在试了下,
这个可以生效
return ($root.ClassesList.list[0].value] || [])
但是下面这个空数组并不能生效,太奇怪了,也就是说,可以在第一个下拉改变的情况下,更改第二个下拉选择的值。但是并不能给他清空

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants