ivew数控件Tree自定义节点内容示例分析
ivew数控件Tree自定义节点内容示例分析
demo地址:https://run.iviewui.com/plcWlM4H
<template>
<Tree :data="data5" :render="renderContent"></Tree>
</template>
<script>
export default {
data () { return {
data5: [
{
title: 'parent 1',
expand: true,
children: [
{
title: 'child 1-1',
expand: true,
children: [
{
title: 'leaf 1-1-1',
expand: true
},
{
title: 'leaf 1-1-2',
expand: true
}
]
},
{
title: 'child 1-2',
expand: true,
children: [
{
title: 'leaf 1-2-1',
expand: true
},
{
title: 'leaf 1-2-1',
expand: true
}
]
}
]
}
],
buttonProps: {
type: 'default',
size: 'small',
}
}
}, //<Icon type="ios-create-outline" /> methods: {
renderContent (h, { root, node, data }) {
//console.log(root, '树的根节点', node, '当前节点', data, '当前节点数据');
/* @root <Array> 把整个树 扁平化 后的 数组
@node <Object> 当前节点
@date <Object> 当前节点数据 nodeKey 每个节点 的唯一标识
parent 父级的 nodeKey */
return h('span', {
class: 'span1',
style: {
display: 'inline-block',
width: '100%'
},
}, [
h('span', [
h('Icon', {
props: {
type: 'ios-paper-outline'
},
class: 'wenjiantubiao',
style: {
marginRight: '8px'
}
}),
h('span', data.title) // 节点标题
]),
h('span', { //右侧操作 包裹
class: 'youcecaozuo',
style: {
display: 'inline-block',
float: 'right',
marginRight: '32px'
}
}, [
h('Button', { //添加按钮
props: Object.assign({}, this.buttonProps, {
icon: 'ios-add'
}),
style: {
marginRight: '8px'
},
on: {
click: () => { this.append(data) }
}
}),
h('Button', { //删除按钮
props: Object.assign({}, this.buttonProps, {
icon: 'ios-remove'
}),
on: {
click: () => { this.remove(root, node, data) }
}
})
])
]);
},
append (data) {
const children = data.children || [];
children.push({
title: 'appended node',
expand: true
});
this.$set(data, 'children', children);
},
remove (root, node, data) {
//console.log(root, node, data, '三个东西');
console.log(node, '确定的node节点');
/*
因为 参数node 是从 root 上引用 处理的 所以 find 时 可以 判断 el对象 和 node 对象是否相等,
详见:https://www.cnblogs.com/taohuaya/p/11535432.html
*/
const parentKey = root.find(el => {
console.log(el, 'root每项');
return el === node;
}).parent; //找到删除项的 父级标识 const parent = root.find(el => el.nodeKey === parentKey).node; //通过 删除的 父级标识 找到 父级元素
const index = parent.children.indexOf(data); //在父级的children数组 中 找到当前删除元素 的索引 index
parent.children.splice(index, 1); //在父级children中 删除掉 要删除的元素
}
}
} /*
render: (h, { root, node, data }) => {
return h('span', {
style: {
display: 'inline-block',
width: '100%'
}
}, [
h('span', [
h('Icon', {
props: {
type: 'ios-folder-outline'
},
style: {
marginRight: '8px'
}
}),
h('span', data.title)
]),
h('span', {
style: {
display: 'inline-block',
float: 'right',
marginRight: '32px'
}
}, [
h('Button', {
props: Object.assign({}, this.buttonProps, {
icon: 'ios-add',
type: 'primary'
}),
style: {
width: '64px'
},
on: {
click: () => { this.append(data) }
}
})
])
]);
}, */ </script>
视图:

ivew数控件Tree自定义节点内容示例分析的更多相关文章
- vue中element-ui树形控件自定义节点,注意一下
在项目中用到菜单项编辑删除,在 element-ui自定义节点内容时, 有说明:使用render-content指定渲染函数, 得环境支持 JSX 语法,只要正确地配置了相关依赖,就可以正常运行. 一 ...
- 验证实现element-ui树形控件的自定义图标及右键菜单
许久不用,element-ui已经更新至2.4.1版本.直接进入今天的正题,前提是node.js的环境还有vue及elment-ui都已经安装.由于element-ui的官方文档中介绍比较粗略,试了许 ...
- Element ui tree树形控件获取当前节点id和父节点id
低版本Element ui tree树形控件获取当前节点id和父节点id的方法:点击查看 最新版本Element ui tree树形控件获取当前节点id和父节点id教程: 1.找到node_modul ...
- element-ui tree控件获取当前节点和父节点
今天使用element-ui 遇到两个问题,第一个问题是获取tree控件的当前节点和父节点, 一开始使用tree控件的getCurrentNode()函数,结果发现返回的是当前节点的data属性,和u ...
- 实用的树形菜单控件tree
jQuery plugin: Treeview 这个插件能够把无序列表转换成可展开与收缩的Tree. jQuery plugin: Treeview jQuery jstree jsTree ...
- VS2010/MFC编程入门之三十一(常用控件:树形控件Tree Control 下)
前面一节讲了树形控件Tree Control的简介.通知消息以及相关数据结构,本节继续讲下半部分,包括树形控件的创建.CTreeCtrl类的主要成员函数和应用实例. 树形控件的创建 MFC为树形控件提 ...
- Merkle 树——空间换时间,分而治之的hash表,通过根节点是由它的两个子节点内容的哈希值组成来校验数据完整性,定位篡改的数据位置
Merkle 树 图 1.5.6.1 - Merkle 树示例 默克尔树(又叫哈希树)是一种二叉树,由一个根节点.一组中间节点和一组叶节点组成.最下面的叶节点包含存储数据或其哈希值,每个中间节点是它的 ...
- VS2010-MFC(常用控件:树形控件Tree Control 下)
转自:http://www.jizhuomi.com/software/203.html 前面一节讲了树形控件Tree Control的简介.通知消息以及相关数据结构,本节继续讲下半部分,包括树形控件 ...
- WebConfig 自定义节点configSections配置信息
WebConfig 自定义节点configSections配置信息 示例: <configuration> <configSections> <!-- For ...
随机推荐
- 给div添加disabled属性
<div id="CompanyId" name="CompanyId" type="select" ></div> ...
- python清理docker-harbor的多余镜像
# coding: utf-8 from operator import itemgetter from urllib import parse import requests import date ...
- ISO/IEC 9899:2011 条款6.9.1——函数定义
6.9.1 函数定义 语法 1.function-definition: declaration-specifiers declarator declaration-listopt ...
- Fiddler抓包工具版面认识(一)
Fiddler是一个蛮好用的抓包工具,可以将网络传输发送与接受的数据包进行截获.重发.编辑.转存等操作.也可以用来检测网络安全.反正好处多多,举之不尽呀!当年学习的时候也蛮费劲,一些蛮实用隐藏的小功能 ...
- 深度学习:21天实战caffe学习资源-4-环境安装
使用anaconda3环境下的python2.7, 机器macos mojave 10.14 1.安装Xcode 首先现在app store中安装Xcode: 不然会有” framework not ...
- SeetaFaceEngine2 实例
LOG: Creating layer(6):LOG: Creating layer(0):LOG: Creating layer(9):LOG: Creating layer(0):LOG: Cre ...
- ES6深入浅出-3 三个点运算 & 新版字符串-2. 新版字符串
这是以前的字符串..双引号,单引号.毫无区别 有时候在字符串里面写一些标签. 排版不好看 我就想回车一下.这样写虽然是好看.但是语法就报错了.es5的字符串不支持换行.我只想是想让它排版的好看一点. ...
- js 实现复制粘贴
js 实现复制粘贴 <!DOCTYPE html> <html><head> <meta http-equiv="Content-Type" ...
- spring 装配bean的混合使用
在现实中,使用XML或者注解各有道理,建议在自己的工程中所开发的类尽量使用注解方式,因为使用它并不困难,甚至可以说更为简单,而对于引入第三方包或者服务的类,尽量使用XML方式,这样的好处是可以尽量对三 ...
- springboot 整合 Froala Editor 3
springboot项目中使用 Froala Editor 3,参考官网文档:https://www.froala.com/wysiwyg-editor/docs/overview 下载文件后,引入c ...