国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vxe-table中樹形結(jié)構(gòu)

這篇具有很好參考價(jià)值的文章主要介紹了vxe-table中樹形結(jié)構(gòu)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

如圖,同事讓幫忙實(shí)現(xiàn)一個(gè)需求

?從二級(jí)樹節(jié)點(diǎn)開始,同時(shí)選中的只能有一個(gè)二級(jí)樹節(jié)點(diǎn),選中的二級(jí)樹節(jié)點(diǎn)之下的子節(jié)點(diǎn)都可以被選中。否則不能被選中

vxe-table中樹形結(jié)構(gòu),arcgis,javascript,html

直接上代碼

需要注意的是,文中樹狀圖傳遞的數(shù)據(jù)是打平的數(shù)據(jù),設(shè)置代碼是下圖,而不是樹狀圖!!

:tree-config="{transform: true, rowField: 'cguid', parentField: 'cparentid'}" 

?上述的這一點(diǎn)非常重要

下面的全乎的數(shù)據(jù)圖

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <!-- 引入樣式 -->
  <link rel="stylesheet" >
  <!-- 引入vue -->
  <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
  <!-- 引入組件 -->
  <script src="https://cdn.jsdelivr.net/npm/xe-utils"></script>
  <script src="https://cdn.jsdelivr.net/npm/vxe-table@3.6.9"></script>
  <script src="data.js"></script>//這個(gè)是我通過js引入的打平的數(shù)據(jù),其中爆露出來的變量是dataList,在第二個(gè)js文件中
</head>

<body>
  <div id="app">
    <vxe-table ref="treeNode" resizable :tree-config="{transform: true, rowField: 'cguid', parentField: 'cparentid'}" :data="tableData"
      :checkbox-config="{labelField: 'cguid', highlight: true,visibleMethod:()=>true,checkMethod:()=>true}"
      @checkbox-change="selectChangeEvent">
      <vxe-column type="checkbox" title="ID" width="280" tree-node></vxe-column>
      <vxe-column field="cname" title="Name"></vxe-column>
    </vxe-table>
  </div>
</body>
1:刪除
2:節(jié)點(diǎn)禁用
3:篩選
<script>
  new Vue({
    el: '#app',
    data: function () {
      return {
        tableData: [], 
        chooseDataTree: null,//選中的樹節(jié)點(diǎn)的內(nèi)容
        data2tree: [],//將打平數(shù)據(jù)封裝成樹結(jié)構(gòu)
      }
    },
    created() {
      this.tableData = dataList;
      //將數(shù)據(jù)改為樹狀結(jié)構(gòu)
      children = getJsonTree(dataList, '000000');
      //遍歷需要這種結(jié)構(gòu)
      this.data2tree = {
        cguid: "000000",
        children,
      }
    },
    methods: {
      selectChangeEvent({ $table, indeterminates, row, records }) {
        console.log(arguments) 
        //將當(dāng)前選中的數(shù)據(jù) 被選中子節(jié)點(diǎn)到root的數(shù)據(jù)
        this.handleCheckChange([...records, ...indeterminates],row)
      },
      handleCheckChange(data,row) {
        //整理成樹狀圖 
        let chooseTree = getJsonTree(data, '000000') 
        //當(dāng)前選中節(jié)點(diǎn)是不是在第一次選中的樹節(jié)點(diǎn)中
        let bool = this.checkMethod({row,chooseTree,chooseList:data})
        console.log('bool:',bool)
        //不再就不讓勾選,同時(shí)提示
        if(!bool){
          this.$refs.treeNode.setCheckboxRow(row,false)
          VXETable.modal.message('當(dāng)前無法被選中')
        }
      }, 
      checkMethod({ chooseList,row ,chooseTree}) {
        //有選中的數(shù)據(jù)
        if (chooseList.length > 0 ) { 
          //已經(jīng)存在選中的tree
          if(this.chooseDataTree){
            //已經(jīng)選中的tree中是否存在當(dāng)前選中的項(xiàng)
            let haveBool = hasChildNode(this.chooseDataTree, row.cguid);
            return haveBool
          }
          //獲取選中的樹表格 
          let chooseTreeData = chooseTree[0];
          //從樹表格中獲取第二級(jí)的節(jié)點(diǎn)(只有選中節(jié)點(diǎn)數(shù)據(jù))
          let leve2Item = chooseTreeData.children[0];
          //從完整的樹表中獲取完整的指定節(jié)點(diǎn)數(shù)據(jù)
          let getThenTree = getLeafNode(this.data2tree, leve2Item.cguid); 
          //將選中的二級(jí)節(jié)點(diǎn)保存起來 用于校驗(yàn)
          this.setChooseDataTree(getThenTree);
          //檢查當(dāng)前節(jié)點(diǎn)是不是在選中的二級(jí)節(jié)點(diǎn)之中 
          let haveBool = hasChildNode(getThenTree, row.cguid);
          console.log('getThenTree:',getThenTree.cname,getThenTree);
          console.log('row:',row.cname,row)
          return haveBool
        } else {
          console.log('選中的內(nèi)容空空如也')
          //將選中內(nèi)容置空
          this.setChooseDataTree(null);
          return true
        }
      },
      //設(shè)置選中后的數(shù)據(jù)內(nèi)容
      setChooseDataTree(data){
        this.chooseDataTree = data
      }
    }

  })

  //講打平的數(shù)據(jù)組將組為樹狀圖
  function getJsonTree(data, cparentid) {
    var result = [], temp;
    for (var i = 0; i < data.length; i++) {
      if (data[i].cparentid == cparentid) {
        if (cparentid === "000000") data[i]['disabled'] = true;
        var obj = { "name": data[i].cname, "id": data[i].cguid };
        obj = Object.assign(obj, data[i]);
        temp = this.getJsonTree(data, data[i].cguid);
        if (temp.length > 0) {
          obj.children = temp;
        }
        result.push(obj);
      }
    }
    return result;
  }
  //指定的節(jié)點(diǎn)中是否包含相應(yīng)的子節(jié)點(diǎn)
  function hasChildNode(root, cguid) {
    if (root == null) {
      return false;
    }
    if (root.cguid === cguid) {
      return true;
    }
    let found = false;
    if (root.children && root.children.length > 0) {
      root.children.forEach(child => {
        if (hasChildNode(child, cguid)) {
          found = true;
        }
      });
    }
    return found;
  }
  //從樹的表格中獲取指定字節(jié)點(diǎn)內(nèi)容數(shù)據(jù)
  function getLeafNode(root, cguid) {
    if (root == null) {
      return null;
    }
    if (root.cguid == cguid) {
      return root;
    }
    let result = null;
    if (root.children && root.children.length > 0) {
      root.children.forEach(child => {
        const leafNode = getLeafNode(child, cguid);
        if (leafNode != null) {
          result = leafNode;
        }
      });
    }
    return result;
  }



</script>

</html>

json打平的數(shù)據(jù)結(jié)構(gòu)是文章來源地址http://www.zghlxwxcb.cn/news/detail-690499.html

const dataList = [
    {
        "cguid": "5422",
        "ccode": "01",
        "cname": "01 資產(chǎn)",
        "cparentid": "000000",
        "ileaf": "0"
    },
    {
        "cguid": "70",
        "ccode": "1004",
        "cname": "1004 匯總科目",
        "cparentid": "5422",
        "ileaf": "0"
    },
    {
        "cguid": "78",
        "ccode": "100401",
        "cname": "100401 匯總科目1",
        "cparentid": "70",
        "ileaf": "1"
    },
    {
        "cguid": "95",
        "ccode": "100402",
        "cname": "100402 匯總科目2",
        "cparentid": "70",
        "ileaf": "1"
    },
    {
        "cguid": "47",
        "ccode": "100403",
        "cname": "100403 匯總科目3",
        "cparentid": "70",
        "ileaf": "1"
    },
    {
        "cguid": "87",
        "ccode": "100404",
        "cname": "100404 匯總科目4",
        "cparentid": "70",
        "ileaf": "0"
    },
    {
        "cguid": "97",
        "ccode": "10040401",
        "cname": "10040401 匯總科目4-1",
        "cparentid": "87",
        "ileaf": "1"
    },
    {
        "cguid": "41",
        "ccode": "90000201",
        "cname": "90000201 B2c1",
        "cparentid": "31",
        "ileaf": "1"
    },
    {
        "cguid": "77",
        "ccode": "90000202",
        "cname": "90000202 B2c2",
        "cparentid": "31",
        "ileaf": "1"
    },
    {
        "cguid": "428",
        "ccode": "1001",
        "cname": "1001 庫xxx",
        "cparentid": "422",
        "ileaf": "1"
    },
    {
        "cguid": "430",
        "ccode": "1002",
        "cname": "1002 銀xxx",
        "cparentid": "422",
        "ileaf": "1"
    },
    
]

到了這里,關(guān)于vxe-table中樹形結(jié)構(gòu)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vxe-table表格合并單元格和編輯

    vxe-table表格合并單元格和編輯

    //這是在vue上面引用vxe-table插件實(shí)現(xiàn)的,主要方法都設(shè)置在table中,mergeCells,tableData都是在vue頁面的data初使化數(shù)據(jù), :footer-method=“footerMethod”:尾部數(shù)據(jù),:merge-footer-items=“mergeCells”:尾部合并單元格。vxe-table網(wǎng)址:https://vxetable.cn/#/table/advanced/footerSpan

    2023年04月09日
    瀏覽(39)
  • vue表格插件vxe-table導(dǎo)出 excel

    vxe-table 默認(rèn)支持導(dǎo)出 CSV、HTML、XML、TXT格式的文件,不支持 xlsx 文件 要想導(dǎo)出 xlsx 文件,需要使用 vxe-table-plugin-export-xlsx 依賴 ?參考:https://cnpmjs.org/package/vxe-table-plugin-export-xlsx/v/2.1.0-beta 1.安裝 ?例子: 如果用最新版的,依賴,這樣使用就會(huì)報(bào)錯(cuò) Uncaught (in promise) 親測(cè)2.2.2版

    2024年01月22日
    瀏覽(29)
  • Vue3 vxe-table 手寫鼠標(biāo)區(qū)域選中

    Vue3 vxe-table 手寫鼠標(biāo)區(qū)域選中

    參考原文地址:vxe-table 鼠標(biāo)滑動(dòng)選擇多行,鼠標(biāo)區(qū)域選中批量操作[2]-CSDN博客 準(zhǔn)備vxe-talbe@4.5.7,Vue@3.3.4,在原作者的基礎(chǔ)上進(jìn)行了修改,修改后和官網(wǎng)幾乎無差別,允許左右側(cè)固定列選中,允許任意范圍選中,但是鍵盤監(jiān)聽功能沒添加//感覺沒啥軟用.... 先看效果: 正常鼠標(biāo)從左上往右下

    2024年02月05日
    瀏覽(29)
  • 前端基礎(chǔ)(Element、vxe-table組件庫的使用)

    前端基礎(chǔ)(Element、vxe-table組件庫的使用)

    前言:在前端項(xiàng)目中,實(shí)際上,會(huì)用到組件庫里的很多組件,本博客主要介紹Element、vxe-table這兩個(gè)組件如何使用。 目錄 Element 引入element 使用組件的步驟 使用對(duì)話框的示例代碼 效果展示? vxe-table 引入vxe-table 成果展示 總結(jié) 官網(wǎng)地址 Button 按鈕 | Element Plus (element-plus.org) 在m

    2024年02月10日
    瀏覽(56)
  • vxe-table 鼠標(biāo)滑動(dòng)選擇多行,鼠標(biāo)區(qū)域選中批量操作

    vxe-table 鼠標(biāo)滑動(dòng)選擇多行,鼠標(biāo)區(qū)域選中批量操作

    該功能存在bug哦,移步我的新博客:vxe-table 鼠標(biāo)滑動(dòng)選擇多行,鼠標(biāo)區(qū)域選中批量操作[2]_wanghanlu_的博客-CSDN博客 在看vxe-table 文檔時(shí),發(fā)現(xiàn)一個(gè)功能,鼠標(biāo)區(qū)域選中,覺得這個(gè)功能很好。 ?但是仔細(xì)發(fā)現(xiàn),這個(gè)功能不是免費(fèi)的。我就想想,為啥不能自己實(shí)現(xiàn)呢。 下面給你看看我的最終

    2024年02月15日
    瀏覽(30)
  • vxe-table 鼠標(biāo)滑動(dòng)選擇多行,鼠標(biāo)區(qū)域選中批量操作[2]

    vxe-table 鼠標(biāo)滑動(dòng)選擇多行,鼠標(biāo)區(qū)域選中批量操作[2]

    前幾天寫了一個(gè)關(guān)于 vxe-table 鼠標(biāo)滑動(dòng)選擇多行 的博客,在項(xiàng)目上線的過程中,發(fā)現(xiàn)這個(gè)功能還是有點(diǎn)bug,在經(jīng)過我對(duì)vxe-table pro版本 的演示后vxe-table PRO,認(rèn)真調(diào)試后,終于解決了bug,并且這個(gè)功能和pro版本可以說是幾乎一模一樣。注意:我是說這個(gè)滑動(dòng)選擇的功能,不是說是

    2024年02月05日
    瀏覽(62)
  • vue3 + vxe-table 封裝通用Grid業(yè)務(wù)組件

    vue3 + vxe-table 封裝通用Grid業(yè)務(wù)組件

    視頻DEMO 功能 基于vxe-table v4 / vxe-grid 全局注冊(cè)組件 無需單獨(dú)引入 動(dòng)態(tài)按需引入樣式vite-plugin-style-import 支持傳入高度 | 默認(rèn)自適應(yīng)高度 自定義表頭 slot,實(shí)現(xiàn)下拉、區(qū)間、日期,并對(duì)表頭參數(shù)進(jìn)行校驗(yàn)(數(shù)字、長(zhǎng)度、指定格式等) 自定義工具欄工具列,重寫自定義列配置項(xiàng),實(shí)現(xiàn)拖拽

    2023年04月08日
    瀏覽(24)
  • vxe-table 小眾但功能齊全的vue表格組件

    vxe-table 小眾但功能齊全的vue表格組件

    一個(gè)基于 vue 的 PC 端表格組件,除了一般表格支持的增刪改查、排序、篩選、對(duì)比、樹形結(jié)構(gòu)、數(shù)據(jù)分頁等,它還支持虛擬滾動(dòng)、懶加載、打印導(dǎo)出、虛擬列表、虛擬滾動(dòng)、模態(tài)窗口、自定義模板、渲染器、賊靈活的配置項(xiàng)、擴(kuò)展接口等,特別是能支持類似excel表格操作方式

    2024年02月08日
    瀏覽(24)
  • 記錄貼:vxe-table單元格合并規(guī)則的簡(jiǎn)單封裝及應(yīng)用

    本文僅做為個(gè)人記錄。 虛擬渲染與單元格合并,可以通過設(shè)置參數(shù) merge-cells 或調(diào)用函數(shù) setMergeCells、setMergeCells 來控制單元格的臨時(shí)合并狀態(tài) (注:合并是以犧牲渲染性能為代價(jià),如果需要用合并建議關(guān)閉虛擬滾動(dòng)) 針對(duì)多層級(jí)的數(shù)組對(duì)象處理,以對(duì)象某個(gè)屬性為準(zhǔn)(此處

    2024年02月02日
    瀏覽(92)
  • vxe-table中<vxe-grid>組件中表格數(shù)據(jù)排序問題sort-change

    vxe-table中<vxe-grid>組件中表格數(shù)據(jù)排序問題sort-change

    問題描述,首先使用vxe-grid虛擬列表為了同時(shí)渲染大批量數(shù)據(jù)的,但是從iview ui里的table和element ui 里table都是只能渲染少量數(shù)據(jù),達(dá)不到大批量數(shù)據(jù)渲染,所以改用vxe-grid。 但是有個(gè)排序的問題在iview ui和element ui 里table都不會(huì)存在排序混亂的問題,而vxe-grid里的排序會(huì)有問題,

    2024年02月16日
    瀏覽(36)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包