• elementui下拉框显示树结构


     https://www.vue-treeselect.cn/

    前端树,下拉框显示树结构 

    :defaultExpandLevel="Infinity" 设置 Infinity 为默认使所有分支节点扩展
    在package.json中加入依赖 :
    "@riophae/vue-treeselect": "^0.4.0",

    前端部分代码:
              <treeselect
                  :options="moduleOptions"
                  style="line-height: 20px; 90%;"       
     
                  :auto-select-ancestors="false"
                  placeholder="请选择所属模块"
                  v-model="moduleForm.module"
                  v-if="projectObj && projectObj.project !== 'init'"
                />
     
    import Treeselect from '@riophae/vue-treeselect'
    import '@riophae/vue-treeselect/dist/vue-treeselect.css'
    
    
      components: {
        Treeselect
      },
    
    
    getAllModule() {
          let param = {}
          let self = this
          commData.getAllModule(param).then(data => {
            if (data.success && data.data) {
              let rootArr = []
              for (let i = 0; i < data.data.length; i++) {
                if (data.data[i].parentId === '0') {
                  rootArr.push(data.data[i])
                }
              }
              this.getMenuChildTree(data.data, rootArr)
            }
          }).catch(e => {
            self.$message.error('服务端出错')
          })
        },
        getMenuChildTree(datas, dataArray) {
          for (let j = 0; j < dataArray.length; j++) {
            let dataArrayIndex = dataArray[j]
            let childrenArray = []
            let Id = dataArrayIndex.id
            for (let i = 0; i < datas.length; i++) {
              let data = datas[i]
              let parentId = data.parentId
              if (parentId === Id) {
                let objTemp = {
                  id: data.id,
                  label: data.module
                }
                childrenArray.push(objTemp)
              }
            }
            if (childrenArray.length > 0) {
              dataArrayIndex.children = childrenArray
              this.getMenuChildTree(datas, childrenArray)
            }
          }
        this.moduleOptions = dataArray
        },
    越努力越幸运~ 加油ヾ(◍°∇°◍)ノ゙
  • 相关阅读:
    P3405 [USACO16DEC]Cities and States S
    P1536 村村通
    P2853 [USACO06DEC]Cow Picnic S
    Springboot整合Swing制作简单GUI客户端项目记录
    Gradle打包可执行jar文件
    gradle配置优化及dependencies中各种依赖方式说明
    Gradle 打可执行jar包
    java swing开发窗体程序开发(四)MVC结构
    Java Swing 图形界面开发(目录)
    使用idea开发普通java项目,使用maven管理依赖,使用slf4j和log4j的配置方案
  • 原文地址:https://www.cnblogs.com/utomboy/p/15745430.html
Copyright © 2020-2023  润新知