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自定义节点内容示例分析的更多相关文章

  1. vue中element-ui树形控件自定义节点,注意一下

    在项目中用到菜单项编辑删除,在 element-ui自定义节点内容时, 有说明:使用render-content指定渲染函数, 得环境支持 JSX 语法,只要正确地配置了相关依赖,就可以正常运行. 一 ...

  2. 验证实现element-ui树形控件的自定义图标及右键菜单

    许久不用,element-ui已经更新至2.4.1版本.直接进入今天的正题,前提是node.js的环境还有vue及elment-ui都已经安装.由于element-ui的官方文档中介绍比较粗略,试了许 ...

  3. Element ui tree树形控件获取当前节点id和父节点id

    低版本Element ui tree树形控件获取当前节点id和父节点id的方法:点击查看 最新版本Element ui tree树形控件获取当前节点id和父节点id教程: 1.找到node_modul ...

  4. element-ui tree控件获取当前节点和父节点

    今天使用element-ui 遇到两个问题,第一个问题是获取tree控件的当前节点和父节点, 一开始使用tree控件的getCurrentNode()函数,结果发现返回的是当前节点的data属性,和u ...

  5. 实用的树形菜单控件tree

     jQuery plugin: Treeview  这个插件能够把无序列表转换成可展开与收缩的Tree. jQuery plugin: Treeview  jQuery  jstree  jsTree ...

  6. VS2010/MFC编程入门之三十一(常用控件:树形控件Tree Control 下)

    前面一节讲了树形控件Tree Control的简介.通知消息以及相关数据结构,本节继续讲下半部分,包括树形控件的创建.CTreeCtrl类的主要成员函数和应用实例. 树形控件的创建 MFC为树形控件提 ...

  7. Merkle 树——空间换时间,分而治之的hash表,通过根节点是由它的两个子节点内容的哈希值组成来校验数据完整性,定位篡改的数据位置

    Merkle 树 图 1.5.6.1 - Merkle 树示例 默克尔树(又叫哈希树)是一种二叉树,由一个根节点.一组中间节点和一组叶节点组成.最下面的叶节点包含存储数据或其哈希值,每个中间节点是它的 ...

  8. VS2010-MFC(常用控件:树形控件Tree Control 下)

    转自:http://www.jizhuomi.com/software/203.html 前面一节讲了树形控件Tree Control的简介.通知消息以及相关数据结构,本节继续讲下半部分,包括树形控件 ...

  9. WebConfig 自定义节点configSections配置信息

    WebConfig 自定义节点configSections配置信息 示例: <configuration>   <configSections>     <!-- For ...

随机推荐

  1. Apache log4j 1.2 - Short introduction to log4j

    Apache log4j 1.2 - Short introduction to log4jhttps://logging.apache.org/log4j/1.2/manual.html log4j ...

  2. MySQL 5.6&5.7 性能优化 TOP10(转)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/NLOneDay/article/deta ...

  3. AndoridSQLite数据库开发基础教程(6)

    AndoridSQLite数据库开发基础教程(6) 为数据库添加添加空表 如果开发者想要往数据库中添加表和列,操作步骤如下: (1)在打开的数据库中,单击左下方的“+”按钮,弹出Table Edito ...

  4. 小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_28..SpringBoot Starter讲解

    笔记 1.SpringBoot Starter讲解     简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-b ...

  5. vue模块化以及封装Storage组件实现保存搜索的历史记录

    <template> <div id="app"> <input type="text" v-model='todo' @keyd ...

  6. React错误收集

    1.  Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/ ...

  7. **209. Minimum Size Subarray Sum 长度最小的子数组

    1. 题目描述 给定一个含有 n 个正整数的数组和一个正整数 s ,找出该数组中满足其和 ≥ s 的长度最小的连续子数组.如果不存在符合条件的连续子数组,返回 0. 示例: 输入: s = 7, nu ...

  8. PAT 甲级 1144 The Missing Number (20 分)(简单,最后一个测试点没过由于开的数组没必要大于N)

    1144 The Missing Number (20 分)   Given N integers, you are supposed to find the smallest positive in ...

  9. 【Leetcode_easy】976. Largest Perimeter Triangle

    problem 976. Largest Perimeter Triangle solution: class Solution { public: int largestPerimeter(vect ...

  10. __proto__和prototype的一些理解

    var Person = function(name) { this.name = name; } var p = new Person(); new操作符的操作是 var p = {} p.__pr ...