element el-tree循环遍历树形结构,并动态赋值disabled属性
凌晨3点,功夫不负有心人,已经累趴,效果终于出来:

看到树形结果,我们首先想到的是肯定需要用到递归了。
贴上代码:
<style scoped>
.form {
width: 50%;
}
</style> <template> <div class="form"> <el-tree
:data="data2"
show-checkbox
node-key="id"
default-expand-all
:props="defaultProps">
</el-tree>
</div> </template> <script>
export default {
data() {
return {
data2: [
{
fs: 0,
id: 1,
label: "一级 1",
children: [
{
fs: 0,
id: 4,
// disabled:true,
label: "二级 1-1",
children: [
{
fs: 1,
id: 9,
label: "三级 1-1-1"
},
{
fs: 1,
id: 10,
label: "三级 1-1-2"
}
]
}
]
},
{
fs: 0,
id: 2,
label: "一级 2",
children: [
{
fs: 0,
id: 5,
label: "二级 2-1"
},
{
fs: 1,
id: 6,
label: "二级 2-2"
}
]
},
{
fs: 0,
id: 3,
label: "一级 3",
children: [
{
fs: 0,
id: 7,
label: "二级 3-1"
},
{
fs: 0,
id: 8,
label: "二级 3-2"
}
]
}
],
defaultProps: {
children: "children",
label: "label"
}
};
},
methods: {
tickMenuIdFilter: function() {
var resultArr = new Array();
var getTickMenuId = function(obj) {
if (undefined == obj || null == obj || !obj instanceof Object) {
return;
}
if (obj.fs > 0) {
// console.log('obj',obj)
obj.disabled = true;
resultArr.push(obj.id);
}
if (null != obj.children && obj.children instanceof Array) {
for (let child of obj.children) {
getTickMenuId(child);
}
}
}; return {
filter: function(arr) {
if (!arr instanceof Array) {
return false;
}
resultArr = new Array();
for (let rootMenu of arr) {
getTickMenuId(rootMenu);
}
return resultArr;
}
};
}
},
created() {
this.tickMenuIdFilter().filter(this.data2);
console.log("data2", this.data2[0].children[0]);
}
};
</script>
备注:也许代码冗余,但是效果亲测出来啦
element el-tree循环遍历树形结构,并动态赋值disabled属性的更多相关文章
- tree:以树形结构显示目录下的内容
tree命令 1.命令详解 [功能说明] tree命令的中文意思为“树”,功能是以树形结构列出指定目录下的所有内容包括所有文件.子目录及子目录里的目录和文件. [语法格式] tree [option] ...
- Linux/Ubuntu tree 命令以树形结构显示文件夹目录结构
1.安装命令工具 sudo apt-get -y install tree 2.可以查看关于tree命令的帮助信息 $ tree --help usage: tree [-adfghilnpqrstu ...
- 【转】linux tree命令以树形结构显示文件目录结构 ---- 不错
原文网址:http://jingyan.baidu.com/article/acf728fd19c7eff8e510a3eb.html 今天小编来给分享Linux 系统下一个非常有用的命令的使用:tr ...
- Vue组件模板形式实现对象数组数据循环为树形结构
数据结构为数组中包含对象--树形结构,用Vue组件的写法实现以下的效果: 树形列表,缩进显示层级,第5级数据加底色,数据样式显色,点击展开折叠数据.本文为用Vue实现方式,另有一篇为用knockout ...
- SAP Tree editor(树形结构)
SAP List Tree 效果 源代码 *&---------------------------------------------------------------------* *& ...
- linux下怎么用tree命令以树形结构显示文件目录结构?
tree命令以树状图列出文件目录结构.不过某些Linux上(Centos 6.4)没有tree命令,本文将介绍安装方法. 常用参数: ? 1 2 3 4 5 6 tree -d 只显示目录. tr ...
- EasyUI使用tree方法生成树形结构加载两次的问题
html代码中利用class声明了easyui-tree,导致easyUI解析class代码的时候先解析class声明中的easyui-tree这样组件就请求了一次url:然后又调用js初始化代码请求 ...
- sql循环查询树形结构
pid:父类别id ' connect by prior pid = id --查询父祖类别 union ' connect by prior id = pid;--查询子孙类别 这样查询出选中id ...
- linux tree命令以树形结构显示文件目录结构
http://jingyan.baidu.com/article/acf728fd19c7eff8e510a3eb.html winscp 传递文件到ubuntu上用winscp
随机推荐
- 问题:Custom tool error: Failed to generate code for the service reference 'AppVot;结果:添加Service Reference, 无法为服务生成代码错误的解决办法
添加Service Reference, 无法为服务生成代码错误的解决办法 我的解决方案是Silverlight+WCF的应用,Done Cretiria定义了需要在做完Service端的代码后首先运 ...
- mybaits中date类型显示时分秒(orcle数据库)
<insert id="insert" parameterType="daSysLoginLog"> insert into DA_SYS_LOGI ...
- Result Maps、Auto-mapping、cache
1. Result Maps resultMap元素是Mybatis里面最重要的并且功能最强大的一个元素.(The resultMapelement is the most important an ...
- junit4新框架hamcrest的assertThat
assertThat JUnit4.4引入了Hamcrest框架,Hamcest提供了一套匹配符Matcher,这些匹配符更接近自然语言,可读性高,更加灵活 /**equalTo匹配符断言被测的tes ...
- 【译】Android 数据库 ORMLite
@DatabaseField cloumnName:指定字段名,不指定则变量名作为字段名 canBeNull:是否可以为null dataType:指定字段的类型 defaultValue:指定 ...
- ubuntu16配置Mask-RCNN
一.安装Anaconda3 1.下载 下载地址:https://www.continuum.io/downloads 2.安装 在文件目录下执行:bash Anaconda3-4.2.0-Linux- ...
- 一堵墙IFC数据-wall.ifc
这是一面墙的IFC数据内容 =====================================文档内容======================================= ISO-1 ...
- ROS Learning-025 (提高篇-003 A Mobile Base-01) 控制移动平台
ROS 提高篇 A Mobile Base-01 - 控制移动平台 - 基本知识 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04.4 ...
- c++ 类中模版成员函数
C++函数模版与类模版. template <class T> void SwapFunction(T &first, T &second){ }//函数模版 templa ...
- 第四章输入/输出(I/O)4.1I/O涉及的设备及相关概念简介
PCL中所有的处理都是基于点云展开的,利用不同的设备获取点云.存储点云等都是点云处理前后必须做的流程,PCL中有自己设计的内部PCD文件格式,为此,设计读写该该格式以及与其他3D文件格式之间进行转化的 ...