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 ...
随机推荐
- Visual Studio 2019更新到16.2.1
Visual Studio 2019更新到16.2.1 此次更新,包含以下修改: (1)支持Xcode 10.3. (2)修复了Forms项目中,预览Android界面效果bug. (3)修复am ...
- org.slf4j:slf4j-api:添加日志管理
org.slf4j:slf4j-api:添加日志管理 转 https://blog.csdn.net/wolfking0608/article/details/77855624 一个好的程序, 完 ...
- linux系统telnet端口不通能收到SYN但不回SYN+ACK响应问题排查(转载)
linux系统telnet端口不通能收到SYN但不回SYN+ACK响应问题排查 一:背景:一台机器从公司办公网登录不上且所有tcp端口都telnet不通,但是通过同机房同的其它机器却可以正常访问到出问 ...
- svn服务端搭建
本文介绍的是SVN的服务器端的搭建. 一.SVN服务器安装 1. 首先来下载和搭建SVN服务器,下载地址如下: http://subversion.apache.org/packages.ht ...
- osgViewer
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source ...
- 【Linux】宝塔上 GitLab数据迁移修改配置后nginx无法启动
背景: 服务器A 向 服务器B 迁移数据,修改配置重启.发现gitlab的 nginx 无法启动. 查找原因 gitlab-ctl tail 错误信息: 网上查了查,似乎是宝塔的问题, 原因应该是为了 ...
- Linux记录-批量安装ssh(转载)
首先,需要检查expect是否安装:rpm -qa|grep expect 然后,在操作机上创建公钥:ssh-keygen 一路回车即可 创建好之后到/root/.ssh/下就可以看到id开头的2个文 ...
- 使用Varnish为网站加速
(1).Varnish概述 Varnish是一款高性能的开源HTTP加速器,可以有效降低web服务器的负载,提升访问速度.根据官方的说法,Varnish是一个cache型的HTTP反向代理. Varn ...
- LeetCode_303. Range Sum Query - Immutable
303. Range Sum Query - Immutable Easy Given an integer array nums, find the sum of the elements betw ...
- JS验证正数字,正则的一种正数规则1
JS中有一个验证数字的方法,就是!isNAN.NAN是非数字,!在JS里表示不是的意思,所以这个!isNAN就是判断不是非数字,也就是是数字.验证某个字符串是否是数字格式是:!isNaN(字符串)经过 ...