首页 > 其他分享 >import treeTransfer from "el-tree-transfer"; 全量树去除 选中的

import treeTransfer from "el-tree-transfer"; 全量树去除 选中的

时间:2023-04-27 22:33:20浏览次数:58  
标签:el toData transfer tree element fromData id children

 <template>
  <div>
    <tree-transfer
      :title="['源列表', '目标列表']"
      :from_data="fromData"
      :to_data="toData"
      :defaultProps="{label:'label'}"
      @add-btn="add"
      @remove-btn="remove"
      :mode="mode"
      height="540px"
      filter
      openAll
    ></tree-transfer>
  </div>
</template>

    <script>
import treeTransfer from "el-tree-transfer"; // 引入
export default {
  components: { treeTransfer }, // 注册
  data() {
    return {
      mode: "transfer", // transfer addressList
      check:[
    {
        "id": "1",
        "pid": 0,
        "label": "一级 1",
        "children": [
            {
                "id": "1-2",
                "pid": "1",
                "label": "二级 1-2",
                "children": [
                    {
                        "id": "1-2-1",
                        "pid": "1-2",
                        "children": [],
                        "label": "二级 1-2-1"
                    },
                    {
                        "id": "1-2-2",
                        "pid": "1-2",
                        "children": [],
                        "label": "二级 1-2-2"
                    }
                ]
            }
        ]
    }
],
      fromData: [],
      resForm: [
        {
          id: "1",
          pid: 0,
          label: "一级 1",
          children: [
            {
              id: "1-1",
              pid: "1",
              label: "二级 1-1",
              // disabled: true,
              children: [],
            },
            {
              id: "1-2",
              pid: "1",
              label: "二级 1-2",
              children: [
                {
                  id: "1-2-1",
                  pid: "1-2",
                  children: [],
                  label: "二级 1-2-1",
                },
                {
                  id: "1-2-2",
                  pid: "1-2",
                  children: [],
                  label: "二级 1-2-2",
                },
              ],
            },
          ],
        },
      ],
      toData: [],
    };
  },
  mounted(){
    // this.fromData=this.resForm
    this.toData=this.check
    this.handlea()
    // this.fromData=this.differenceTree()
  },
  methods: {
    // 切换模式 现有树形穿梭框模式transfer 和通讯录模式addressList
    changeMode() {
      if (this.mode == "transfer") {
        this.mode = "addressList";
      } else {
        this.mode = "transfer";
      }
    },
    // 监听穿梭框组件添加
    add(fromData, toData, obj) {
      // 树形穿梭框模式transfer时,返回参数为左侧树移动后数据、右侧树移动后数据、移动的{keys,nodes,halfKeys,halfNodes}对象
      // 通讯录模式addressList时,返回参数为右侧收件人列表、右侧抄送人列表、右侧密送人列表
      console.log("fromData:", fromData);
      console.log("toData:", toData);
      console.log("obj:", obj);
    },
    // 监听穿梭框组件移除
    remove(fromData, toData, obj) {
      // 树形穿梭框模式transfer时,返回参数为左侧树移动后数据、右侧树移动后数据、移动的{keys,nodes,halfKeys,halfNodes}对象
      // 通讯录模式addressList时,返回参数为右侧收件人列表、右侧抄送人列表、右侧密送人列表
      console.log("fromData:", fromData);
      console.log("toData:", toData);
      console.log("obj:", obj);
    },
    handlea(){
      const ids = [];
      function getIds(array) {
        for (let i = 0; i < array.length; i++) {
          const element = array[i];
          ids.push(element.id);
          if (element.children && element.children.length > 0) {
            getIds(element.children);
          }
        }
      }
      if (this.toData.length > 0) {
        getIds(JSON.parse(JSON.stringify(this.toData)));
        this.fromData = this.differenceTree(ids, JSON.parse(JSON.stringify(this.resForm)));
        console.log(this.fromData);
        return;
      }
    },
    //树过滤
    differenceTree(ids, arr) {
      const newarr = [];
      arr.forEach((element) => {
        if (ids.indexOf(element.id) == -1) {
          // 判断条件
          newarr.push(element);
        } else if (element.children && element.children.length > 0) {
          const redata = this.differenceTree(ids, element.children);
          if (redata && redata.length > 0) {
            const obj = {
              ...element,
              children: redata,
            };
            newarr.push(obj);
          }
        }
      });
      return newarr;
    },
  },
};
</script>

    <style>
</style>

标签:el,toData,transfer,tree,element,fromData,id,children
From: https://www.cnblogs.com/7c89/p/17360430.html

相关文章

  • 【牛客编程题】shell34题(Linux awk,grep命令)
    【牛客编程题】shell34题(Linuxawk,grep命令)SHELL01-22:基本文本处理SHELL23-28:nginx日志分析SHELL29-32:netstat练习做题链接:https://www.nowcoder.com/exam/oj?page=1&tab=SHELL%E7%AF%87&topicId=195参考资料:https://github.com/jaywcjlove/linux-command文章目录从awk命令开始对......
  • mybatis定义sql语句标签之select 标签
    属性介绍:id:唯一的标识符.和Mapper接口定义方法名同名。parameterType:传给此语句的参数的全路径名或别名例:com.test.poso.User或user,目前很少用到。resultType:语句返回值类型或别名。注意,如果是集合,那么这里填写的是集合的泛型,而不是集合本身(resultType与resultMap不......
  • P1345 [USACO5.4]奶牛的电信Telecowmunication 题解
    一、题目描述:n个点,m条边,给定起点s和终点t,求最少删去几个点后,s和t不连通。注意,s和t不能删掉。1<=n<=100,1<=m<=600; 二、解题思路:刚刚学了最大费用流,知道最大流等于最小割。但此题割的不是边,是点。我们需要将将割点转化为割边。把一个点切成两半......
  • Selenium自动化测试面试题
    Selenium自动化测试面试题一、目录1、什么是自动化测试、自动化测试的优势是什么?2、什么样的项目比较适合做自动化测试,什么样的不适合做自动化测试?3、说一下开展自动化工作的主要流程是怎样的?4、在制定自动化测试计划的时候一般要考虑哪些点?5、编写自动化脚本时的一些规范?6、......
  • 使用Excel来整理数据
      日常工作中经常会遇到“导数据”的需求,大多数时候,丢过来的Excel数据都是不符合数据库要求的,没办法直接通过程序去导入,即使是按照程序要求的模板,导入过程也可能因为各种格式问题导入失败,而往往失败后的调试跟踪要花大量时间和精力。而导入这项工作很多时候又恰恰只需要做一次就......
  • 新项目删除SceneDelegate以及创建PrefixHeader文件
    1.新项目删除SceneDelegate删除SceneDelegate文件info.plist文件中删除ApplicationSceneManifest中的item删除SceneDelegate在AppDelegate中的代理在AppDelegate.h添加window小问题:2.新项目plist文件的移动buildSeting里搜索info.plistFile设置路径3.......
  • elementUI表格默认多选
    this.multipleSelection=row.mer_type_idthis.$nextTick(()=>{this.multipleSelection.forEach(id=>{constrow=this.categoryMerTypeList.find(item=>item.mer_type_id==id);this.$refs.multipleTable.toggleRowSelection(row,true);});})......
  • Python MatplotlibDeprecationWarning Matplotlib 3.6 and will be removed two minor
    在Pycharm中使用Matplotlib中的pyplot时,运行代码报错:MatplotlibDeprecationWarning:SupportforFigureCanvaseswithoutarequired_interactive_frameworkattributewasdeprecatedinMatplotlib3.6andwillberemovedtwominorreleaseslater.解决方法File->Set......
  • js javascript 鼠标触碰select下拉列表渐变出div层,鼠标离开渐变缩回
    <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-......
  • asp.net c# webform 三层架构,bll,dal,model,dbcommon
    BLL:业务层相当于struts里的action,控制业务逻辑Model:数据实体,相当于struts里的bean,持久化数据的,有set,getDAL:数据层,用来拼凑sql语句DBCommon:与数据库打交道的层,用来CRUD连接数据库等这是我今天学三层了,做了个三层的登陆例子的总结经验,我对三层......