bootstrap treeview 树形数据生成
这个问题还是挺经典的,后台只是负责查出所有的数据,前台js来处理数据展示给treeview;
show you the code below:
<script>
$(function () {
getData(); })
var displaySeach = function(){
if($("#search-page .x_content").is(":hidden"))
$('#search-page .x_content').slideDown(300);
else
$('#search-page .x_content').slideUp(300);
}
function getTree() {
//节点上的数据遵循如下的格式:
var tree = [{
text: "场地列表", //节点显示的文本值 string
icon: "glyphicon glyphicon-play-circle", //节点上显示的图标,支持bootstrap的图标 string
selectedIcon: "glyphicon glyphicon-ok", //节点被选中时显示的图标 string
color: "#ff0000", //节点的前景色 string
backColor: "#1606ec", //节点的背景色 string
selectable: true, //标记节点是否可以选择。false表示节点应该作为扩展标题,不会触发选择事件。 string
state: { //描述节点的初始状态 Object
checked: true, //是否选中节点
/*disabled: true,*/ //是否禁用节点
expanded: true, //是否展开节点
selected: true //是否选中节点
}
}]
return tree;
} function getData() {
$.ajax({
type: "GET",
url: "/serverPoint/index",
success: function (data) {
console.log("data", data);
for (var k = 0; k < data.length; k++) {
data[k]['text'] = data[k]['Name'];
}
var tree = [{
text: "场地列表", //节点显示的文本值 string
icon: "glyphicon glyphicon-play-circle", //节点上显示的图标,支持bootstrap的图标 string
selectedIcon: "glyphicon glyphicon-ok", //节点被选中时显示的图标 string
color: "#ff0000", //节点的前景色 string
backColor: "#1606ec", //节点的背景色 string
selectable: true, //标记节点是否可以选择。false表示节点应该作为扩展标题,不会触发选择事件。 string
state: { //描述节点的初始状态 Object
checked: true, //是否选中节点
/*disabled: true,*/ //是否禁用节点
expanded: true, //是否展开节点
selected: true //是否选中节点
},
nodes: toTree(data)
}] $('#tree').treeview({
data: tree,//节点数据
showBorder: true, //是否在节点周围显示边框
showCheckbox: true, //是否在节点上显示复选框
showIcon: true, //是否显示节点图标
highlightSelected: true,
levels: 2,
multiSelect: true, //是否可以同时选择多个节点
showTags: true
});
},
error: function () {
$.pnotify({
title: '失败提醒',
text: '请求服务器失败',
type: 'error',
nonblock: {
nonblock: false
},
});
}
}); } function toTree(data) {
// 删除 所有 children,以防止多次调用
data.forEach(function (item) {
delete item.nodes;
}); // 将数据存储为 以 id 为 KEY 的 map 索引数据列
var map = {};
data.forEach(function (item) {
map[item.ID] = item;
});
// console.log(map);
var val = [];
data.forEach(function (item) {
// 以当前遍历项,的pid,去map对象中找到索引的id
var parent = map[item.ParentID];
// 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
if (parent) {
(parent.nodes || (parent.nodes = [])).push(item);
} else {
//如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
val.push(item);
}
});
return val;
} $('.place-choice').on('change', function () {
var cityNum = $(this).val();
console.log("cityNum:", cityNum);
addPlaceSelect($(this), cityNum);
}); var addPlaceSelect = function (obj, cityNum) {
console.log("addPlaceSelect....................");
obj.nextAll().remove();
$.ajax({
url: '/serverPoint/getChild/' + cityNum,
type: 'get',
data: {},
success: function (data) {
if (data) {
if (data.length > 0) {
console.log('data.length > 0');
var select = $('<select></select>');
select.addClass('select2_single form-control place-choice').css('margin-right', '5px').css('width', '100px').css('float', 'left');
$('.place-choice-td').append(select);
select.on('change', function () {
var cityNum = $(this).val();
addPlaceSelect($(this), cityNum);
});
var str = '<option value="">请选择</option>';
select.append(str);
for (var i = 0; i < data.length; i++) {
var str = '<option value="' + data[i]['ID'] + '">' + data[i]['Name'] + '</option>';
select.append(str);
}
}
} else {
$.pnotify({
title: '失败提醒',
text: '添加分类失败',
type: 'error',
nonblock: {
nonblock: false
},
});
}
},
error: function () {
$.pnotify({
title: '失败提醒',
text: '请求服务器失败',
type: 'error',
nonblock: {
nonblock: false
},
});
}
}); } function addNode(pid=null) {
var parentId='';
if (pid == -1) {
var text = $('#postition-name').val();
console.log('text:',text);
parentId = 0;
if (text == "" || text.length == 0) {
$.pnotify({
title: '温馨提醒',
text: '请先填写名称',
type: 'error',
nonblock: {
nonblock: false
},
});
return;
}
} else {
parentId = $('.place-choice-td select:last-child').val();
console.log(parentId);
var text = $('#sub-postition-name').val();
if (parentId == "" || parentId.length == 0) {
$.pnotify({
title: '温馨提醒',
text: '请先选择场景',
type: 'error',
nonblock: {
nonblock: false
},
});
return;
}
if (text == "" || text.length == 0) {
$.pnotify({
title: '温馨提醒',
text: '请先填写名称',
type: 'error',
nonblock: {
nonblock: false
},
});
return;
}
}
$.ajax({
url: '/serverPoint/add',
type: 'post',
data: {
'parentId': parentId,
'name': text
},
success: function (data) {
$.pnotify({
title: '成功提醒',
text: '添加成功',
type: 'success',
nonblock: {
nonblock: false
},
});
getData();
},
error: function () {
$.pnotify({
title: '失败提醒',
text: '请求服务器失败',
type: 'error',
nonblock: {
nonblock: false
},
});
}
}); }
/* function getTree() {
//节点上的数据遵循如下的格式:
var tree = [{
text: "Node 1", //节点显示的文本值 string
icon: "glyphicon glyphicon-play-circle", //节点上显示的图标,支持bootstrap的图标 string
selectedIcon: "glyphicon glyphicon-ok", //节点被选中时显示的图标 string
color: "#ff0000", //节点的前景色 string
backColor: "#1606ec", //节点的背景色 string
href: "#http://www.baidu.com", //节点上的超链接
selectable: true, //标记节点是否可以选择。false表示节点应该作为扩展标题,不会触发选择事件。 string
state: { //描述节点的初始状态 Object
checked: true, //是否选中节点
/!*disabled: true,*!/ //是否禁用节点
expanded: true, //是否展开节点
selected: true //是否选中节点
},
//tags: ['标签信息1', '标签信息2'], //向节点的右侧添加附加信息(类似与boostrap的徽章) Array of Strings
nodes: getData()
}]
return tree;
}*/
/*function getData(){
$.ajax({
type: "GET",
url: "/serverPoint/index",
success:function(data){
console.log(JSON.stringify(data));
return JSON.stringify(data);
},
error:function() {
}
}); }*/
</script>
bootstrap treeview 树形数据生成的更多相关文章
- 基于Bootstrap的JQuery TreeView树形控件,数据支持json字符串、list集合(MVC5)<二>
上篇博客给大家介绍了基于Bootstrap的JQuery TreeView树形控件,数据支持json字符串.list集合(MVC5)<一>, 其中的两种方式都显得有些冗余.接着上篇博客继续 ...
- TreeView树形控件递归绑定数据库里的数据
TreeView树形控件递归绑定数据库里的数据. 第一种:性能不好 第一步:数据库中查出来的表,字段名分别为UNAME(显示名称),DID(关联数据),UTYPE(类型) 第二步:前台代码 <% ...
- SharePoint2010沙盒解决方案基础开发——关于TreeView树形控件读取列表数据(树形导航)的webpart开发及问题
转:http://blog.csdn.net/miragesky2049/article/details/7204882 SharePoint2010沙盒解决方案基础开发--关于TreeView树形控 ...
- Bootstrap treeview增加或者删除节点
参考(AddNode: http://blog.csdn.net/qq_25628235/article/details/51719917,deleteNode:http://blog.csdn.ne ...
- 初始化bootstrap treeview树节点
最近在做启明星图库时,使用了Jquery Bootstrap Treeview插件.但是,遇到了一个初始化的问题.先看效果如下: 当用户打开图库时,左边分类第一个类别是“所有分类”,默认需要选中. ...
- Web中树形数据(层级关系数据)的实现—以行政区树为例
在Web开发中常常遇到树形数据的操作,如菜单.组织机构.行政区(省.市.县)等具有层级关系的数据. 以下以行政区为例说明树形数据(层级关系数据)的存储以及实现,效果如图所看到的. 1 数据库表结构设计 ...
- 大数据技术之_25_手机APP信息统计系统项目_01_APP 数据生成模块 + 数据收集模块 + 数据处理模块框架搭建 + 业务需求处理 + 数据展示模块 +项目总结 + 问题总结
一 项目概述1.1 角色1.2 业务术语1.3 项目效果展示二 项目需求三 项目概要3.1 项目技术架构3.2 项目目录结构3.3 项目技术选型3.4 项目整体集群规划3.5 创建项目工程四 APP ...
- html 报告页面 v1.2 批量数据生成表格
html 报告页面 v1.2 批量数据生成表格 上代码: <!DOCTYPE html> <html lang="en"> <head> < ...
- Asp.Net Mvc自定义控件之树形结构数据生成表格 - WPF特工队内部资料
最近项目中有一个需求,将树形结构的数据,以表格的形式展示在页面中,下图是最终呈现效果: 源码: @{ Layout = null; } <!DOCTYPE html> <html&g ...
随机推荐
- Ubuntu忘记超级用户root密码,重新设置密码
Ubuntu版本:Ubuntu 16.04.3 LTS 1启动系统,在启动过程中,反复按Esc键或者shift键(本人亲测反复按或者长按都可以,没必要纠结),直到出现以下界面: 通过上下键移动,选择U ...
- 记数据库数据文件损坏恢复ORA-00376+ORA-01110
现象:业务平台无法登陆,日志报错为ORACLE的错误. 查看oracle日志的报错, ORA-00376: file 5 cannot be read at this time ORA-01110: ...
- Mybatis学习 day02
第十六章回顾SQL99中的连接查询 1)内连接 2)外连接 3)自连接 第十七章回顾hibernate多表开发 1)一对一 2)一对多 3)多对多 第十八章 mybatis一对一映射[学生与身份证] ...
- SQL SERVER 死锁
sp_lock 查看锁表名称 select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableNamefr ...
- 有了这个api接口工具-微信跳转其他浏览器下载app就这么简单
现在微信渠道可以说是拉新最快的渠道,因为微信具备强裂变性.但是目前微信对第三方下载链接的拦截是越来越严格了,那么想要在微信内肆无忌惮地推广链接就需要用到微信跳转浏览器的api接口,那如何获取该api接 ...
- Python学习日记 --day2
Python学习日记 --day2 1.格式化输出:% s d (%为占位符 s为字符串类型 d为数字类型) name = input('请输入姓名') age = int(input('请输入年龄 ...
- python3列表(元组)练习
列表和元组一起练习l = [] 或者 li = list() 列表表示t = () 元组表示,元组不能修改,元组中只有两个方法 count().index(),同列表相同 li = [11,22,33 ...
- splash介绍及安装_mac
一.splash介绍 Splash是一个Javascript渲染服务.它是一个实现了HTTP API的轻量级浏览器,基于Python3和Twisted引擎,可以异步处理任务,并发性能好. 二.spla ...
- 程序配置的原则和实践以及 Spring Boot 支持方式
原则 软件需要在不同的环境中部署,代码是保持不变的,但是不同的运行环境存在差异,所以需要使用配置适应不同的环境.比如: 数据库,Redis,以及其他 后端服务 的配置: 第三方服务的证书,如 oAut ...
- mac 环境搭建
安装homebrew jdk 也可以官网下载 maven 官网下载tar.gz包 也在homebrew下安装git,java,mysql.