利用js实现添加多级树形插件



18 70 24



特效描述:利用js实现 添加多级 树形插件,利用js实现添加多级树形插件

代码结构

1. 引入CSS

<link rel="stylesheet" href="assets/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="assets/css/tree.css" media="all" />

2. 引入JS

<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/layui/layui.js"></script>
<script type="text/javascript" src="assets/js/vue.min.js"></script>
<script type="text/javascript" src="assets/js/tree.js"></script>

3. HTML代码

<div id="vm">
	<div class="layui-elem-field">
		<form class="layui-form" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">树形插件</label>
				<div class="layui-input-block">
					<item v-bind:tree='treeData' id='tree'></item>
				</div>
			</div>
		</form>
	</div>
	<!-- 添加节点 -弹窗-->
	<div class="layui-row" id="addNodelayer" style="display: none;margin-top: 30px">
		<form class="layui-form" action="" method="post" enctype="multipart/form-data" id="formid1">
			<div class="layui-form-item">
				<label class="layui-form-label">节点名称</label>
				<div class="layui-input-inline">
					<input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<span class="layui-btn" lay-submit lay-filter="addDataBtn">确认添加</span>
				</div>
			</div>
		</form>
	</div>
	<!-- 编辑编辑 -弹窗-->
	<div class="layui-row" id="editNodelayer" style="display: none;margin-top: 30px">
		<form class="layui-form" action="" method="post" enctype="multipart/form-data" id="formid2">
			<div class="layui-form-item">
				<label class="layui-form-label">分类名称</label>
				<div class="layui-input-inline">
					<input type="text" name="className" v-model='name' required lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<span class="layui-btn" lay-submit lay-filter="editDataBtn">确认修改</span>
				</div>
			</div>
		</form>
	</div>
</div>
<template id='treeTemplate'>
	<ul class="tree-box">
		<li class="tree-item" v-for='(v,i) in tree'> 
			<div class="tree-info-box">
				<i  class="layui-icon" :class="[ tree[i].open ? 'layui-icon-triangle-r' :' layui-icon-triangle-d']" v-if="isFolder(v)" @click="toggle(i)"></i>
				<i v-else  class="layui-icon layui-icon-file"></i>
				<span :data-id="i" class="title-name"  @click="changeCheck(i)" >{{v.name}}</span> 
				<div class="tree-btn-group">
					<span class="add-node-btn node-btn" @click="addNode(i)"> <i class="layui-icon layui-icon-add-1"></i> 添加下一级</span>
					<span class="edit-node-btn node-btn" @click="editNode(i)"> <i class="layui-icon layui-icon-edit"></i> 编辑</span>
					<span class="del-node-btn node-btn" @click="delNode(i)"> <i class="layui-icon layui-icon-delete"></i> 删除</span>
				</div> 
			</div>
			<item v-bind:tree='v.child' v-show="tree[i].open" style="margin-left: 20px;"></item>
		</li>
	</ul> 
</template>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
</div>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 切换按钮 表单 表单美化 表单插件 表单美化插件 添加删除 添加标签

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到