后台获取数据形式 (parentID=0的是父级,parentID不为0的,如果parentID与某个对象中的id相等,则表示为该对象的子级。)

 代码转换:

<script>  
var roomMenuDataL;//后台获取的教室数据
methods: {
    //获取教室树
    getroommenu() {
      const token = this.$cookieTools.getToken();
      //获取token
      const getmenuurl = "/usiop/sysroomtree/usedittreeselect?token=" + token;
      this.$myaxios.post(getmenuurl).then((res) => {
        // console.error(res);
        if (res.result == 0 && res.data.length > 0) {
          roomMenuDataL=res.data;
          //调用方法进行数据转换为childern形式
          this.roomMenuData = this.$options.methods.getroomtreedata("-1");
          console.error(this.roomMenuData);
        } else {
        }
      });
    },
// 将数据递归转换 getroomtreedata: function (pid) {
const child = roomMenuDataL.filter((item) => item["pId"] === pid); return child.map((item) => { if (this.getroomtreedata(item.id).length > 0) { return { ...item, payType: [1], label: item.className, value: item.id, children: this.getroomtreedata(item.id), disabled: true, }; } else { return { ...item, payType: [1], label: item.className, value: item.id, disabled: false, }; } }); }, }, </script>

 转换成功:

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。