# 编辑select联动操作

An image


//获取表单配置
getOption(field) {
    for (let index = 0; index < this.editFormOptions.length; index++) {
      const _options = this.editFormOptions[index]
      const obj = _options.find((c) => {
        return c.field == field
      })
      if (obj) {
        return obj
      }
    }
  },
onInit() {
      //获取select【地区】配置
      let cityOption = this.getOption("City");//City改为要操作的字段
      //获取select【是否启用】配置
      let enableOption = this.getOption("Enable");//Enable改为要操作的字段
      //通过cityOption选择后,给select2重新绑定数据源与textare重新设置值
      let source = [];
      //添加下拉框选中事件
      cityOption.onChange = (val, option) => {
        //通过http从后台加载数据源
        //this.http.post(url, {}, true).then(source => {
            //后台返回数据源格式
            source = [ { key: "1", value: "text1"},{ key: "2", value: "text2"}];

            //注意:如果返回的数据数组长度超过500,请在onInit的第一行加上this.select2Count=100000;
            //重新绑定数据源
            enableOption.data = source;

            //给enableOption标签设置默认选中值
            // if (source.length) {
            //   this.editFormFields[enableOption.field] = source[0].key+"";
            // }
        //})
      }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

# 查询表单select联动操作

 //操作方式同上一样,只是将this.editFormOptions改为this.searchFormOptions
1