表单中需要多选 内容时

85 阅读1分钟

前端4.png

可选择服务类别的内容

qiadn.png

当下标为9 对应文中下标current9

前端3.png qiadn.png

cur[idx] 是如果是当value的值等于current的下标

前端.png

自己通过定义新数组TypeAry接收

前端6.png

e.detail.value 当前所属服务类别这个下标数字 数据处理完 进行去重 new Set 再将 定义的TypeAry进行删除 只保留后面内容 再将内容 赋值 TypeAry

前端5.png

页面调用方法 操作

前端1.png

bindPicker(e) {
    console.log(e);
    var paramName = e.currentTarget.dataset["param"]
    var value = ''
    var idx = e.currentTarget.dataset["index"]
    var ary = null;
    var cur = this.data.current
    if (idx == 0) ary = this.data.regionAry
    if (idx == 2) ary = this.data.cardTypeAry
    if (idx == 4) ary = this.data.sexAry
    if (idx == 7) ary = this.data.serverRegionAry
    if (idx == 9){
      ary = this.data.serverTypeAry
      cur[idx] = value
      // console.log(this.data.TypeAry);
      let arr = []
      let str = ''
      // console.log(this.data.TypeAry)
      str = this.data.serverTypeAry[e.detail.value]
      // console.log(str);
      arr = this.data.TypeAry
      // console.log(arr);
      arr.push(str)
      // console.log(arr);
      let str1 = [...new Set(arr)]
      // console.log(str1);
  
      if(str1[0] =="请选择服务类别"){
        str1.splice(str1[0], 1)
      }
      this.setData({
        TypeAry : str1
      })