bootstrap-treeview使用
1.数据
var tree = [{
text: "车型A",
nodes: [{
text: "车系1",
},
{
text: "车系2"
}, {
text: "车系3"
}
]
},
{
text: "车型B",
nodes: [{
text: "车系4",
},
{
text: "车系5"
}, {
text: "车系6"
}
]
}, {
text: "车型C",
nodes: [{
text: "车系7",
},
{
text: "车系8"
}, {
text: "车系9"
}
]
}
];
2.方法拓展
var OtherTree = function(treeDom) {
var othis = this;
othis.treeDom = treeDom;
othis.nodeCheckedSilent = false;
othis.nodeChecked = (event, node) => {
if(othis.nodeCheckedSilent) {
return
}
othis.nodeCheckedSilent = true;
othis.checkAllParent(node);
othis.checkAllSon(node);
othis.nodeCheckedSilent = false;
};
othis.nodeUncheckedSilent = false;
othis.nodeUnchecked = (event, node) => {
if(othis.nodeUncheckedSilent) return;
othis.nodeUncheckedSilent = true;
othis.uncheckAllParent(node);
othis.uncheckAllSon(node);
othis.nodeUncheckedSilent = false;
};
//选中全部父节点
othis.checkAllParent = (node) => {
othis.treeDom.treeview('checkNode', node.nodeId, {
silent: true
});
var _siblings = othis.treeDom.treeview('getSiblings', node.nodeId);
var _parentNode = othis.treeDom.treeview('getParent', node.nodeId);
if(!("nodeId" in _parentNode)) {
return;
} else {
var _isAllUnchecked = true; //是否全部选中
for(var i in _siblings) {
if(!(_siblings[i].state.checked)) {
_isAllUnchecked = false;
break;
}
}
if(_isAllUnchecked) {
othis.checkAllParent(_parentNode);
}
}
};
//取消全部父节点
othis.uncheckAllParent = (node) => {
othis.treeDom.treeview('uncheckNode', node.nodeId, {
silent: true
});
var _siblings = othis.treeDom.treeview('getSiblings', node.nodeId);
var _parentNode = othis.treeDom.treeview('getParent', node.nodeId);
if(!("nodeId" in _parentNode)) {
return;
}
var _isAllUnchecked = true; //是否有一个没选中
for(var i in _siblings) {
if(!(_siblings[i].state.checked)) {
_isAllUnchecked = true;
break;
}
}
if(_isAllUnchecked) {
othis.uncheckAllParent(_parentNode);
}
};
//级联选中所有子节点
othis.checkAllSon = (node) => {
othis.treeDom.treeview('checkNode', node.nodeId, {
silent: true
});
if(node.nodes != null && node.nodes.length > 0) {
for(var i in node.nodes) {
othis.checkAllSon(node.nodes[i]);
}
}
};
//级联取消所有子节点
othis.uncheckAllSon = (node) => {
othis.treeDom.treeview('uncheckNode', node.nodeId, {
silent: true
});
if(node.nodes != null && node.nodes.length > 0) {
for(var i in node.nodes) {
othis.uncheckAllSon(node.nodes[i]);
}
}
};
}
3.使用
function initTreeView() {
var _othertree = new OtherTree($tree_view);
$tree_view.treeview({
data: tree,
showCheckbox: true,
color: "#999",
selectedBackColor: "#f5f5f5",
selectedColor: "#999",
multiSelect: true,
levels: 5,
onNodeChecked: function(event, node) {
_othertree.nodeChecked(event, node);//调用拓展方法
},
onNodeUnchecked: function(event, node) {
_othertree.nodeUnchecked(event, node);//调用拓展方法
}
});
}
4.回显
var treeArrData = $tree_view.treeview('getUnchecked');//获取所有tree所有的node
if(row.activityModelList) {//返回的对象
var modelList = row.activityModelList.split(',');
var checkArr = [];
for(var i = 0; i < modelList.length; i++) {
for(var j = 0; j < treeArrData.length; j++) {
if(treeArrData[j].text == modelList[i]) {//取nodeId
$tree_view.treeview('checkNode', treeArrData[j].nodeId, {
silent: true
});
}
}
};
}
5.适用
父节点选中子节点全部选中,子节点取消一个父节点自动取消
bootstrap-treeview使用的更多相关文章
- Bootstrap treeview增加或者删除节点
参考(AddNode: http://blog.csdn.net/qq_25628235/article/details/51719917,deleteNode:http://blog.csdn.ne ...
- 初始化bootstrap treeview树节点
最近在做启明星图库时,使用了Jquery Bootstrap Treeview插件.但是,遇到了一个初始化的问题.先看效果如下: 当用户打开图库时,左边分类第一个类别是“所有分类”,默认需要选中. ...
- BootStrap TreeView使用示例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- bootstrap treeview 树形数据生成
这个问题还是挺经典的,后台只是负责查出所有的数据,前台js来处理数据展示给treeview;show you the code below:<script> $(function () { ...
- bootstrap treeview实现菜单树
本博客,介绍通过Bootstrap的treeview插件实现菜单树的功能. treeview链接:http://www.htmleaf.com/Demo/201502141380.html ORM框架 ...
- MVC5 网站开发之六 管理员 2、添加、删除、重置密码、修改密码、列表浏览
目录 奔跑吧,代码小哥! MVC5网站开发之一 总体概述 MVC5 网站开发之二 创建项目 MVC5 网站开发之三 数据存储层功能实现 MVC5 网站开发之四 业务逻辑层的架构和基本功能 MVC5 网 ...
- MVC5 网站开发之八 栏目功能 添加、修改和删除
本次实现栏目的浏览.添加.修改和删除. 栏目一共有三种类型. 常规栏目-可以添加子栏目,也可以添加内容模型.当不选择内容模型时,不能添加内容. 单页栏目-栏目只有一个页面,可以设置视图. 链接栏目-栏 ...
- 再谈Newtonsoft.Json高级用法
上一篇Newtonsoft.Json高级用法发布以后收到挺多回复的,本篇将分享几点挺有用的知识点和最近项目中用到的一个新点进行说明,做为对上篇文章的补充. 阅读目录 动态改变属性序列化名称 枚举值序列 ...
- 【转】C#解析Json Newtonsoft.Json
Newtonsoft.Json源码 Newtonsoft.Json介绍 在做开发的时候,很多数据交换都是以json格式传输的.而使用Json的时候,我们很多时候会涉及到几个序列化对象的使用:DataC ...
- django权限二(多级菜单的设计以及展示)
多级权限菜单设计级标题栏 我们现在只有数据展示,要进入其他url还需要手动的输入路径,非常的麻烦,所以我们要设计 一个导航栏以及侧边多级菜单栏,这个展示是通过stark组件的设计的增删改查页面,而 每 ...
随机推荐
- Java 之常用API(二)
Object类 & System类 日期相关类 包装类 & 正则表达式 Object类 & System类 1.1 Object类 1.1.1 概述 Object类是Java语 ...
- 直到黎明 Until Dawn 后感
直到黎明 会免游戏.白金神作.近些年的恐怖电影都有游戏化的趋势,韩国的某岩vlog,美国的真心话大冒险,都把观众作为meta代入游戏,几乎模糊了游戏与游戏的边界,直到黎明这部电影,与当年的暴雨和超凡双 ...
- ubuntu-15.04-desktop-amd64想要安装KDE桌面,结果出现如下问题
The following packages have unmet dependencies: kubuntu-desktop : Depends: ark but it is not going t ...
- Sqlite 语句 记录
//string ComId = "select Max(ComId) AS ComId from Card order by ComId ";//位数一样可以直接MAx stri ...
- MySQL · 数据恢复 · undrop-for-innodb
Ref:https://www.aliyun.com/jiaocheng/1109809.html 摘要: 简介 undrop-for-innodb 是针对 innodb 的一套数据恢复工具,可以从 ...
- jsp 页面间传递参数
JSP页面间传递参数是经常需要使用到的功能,有时还需要多个JSP页面间传递参数.下面介绍一下实现的方法. (1)直接在URL请求后添加 如:< a href="thexuan.jsp? ...
- springmvc处理日期格式
解决http400错误 通常有两个来源: 1 页面的下拉列表中传入了字符串,而服务器需要的是Integer类型的,所以服务器拒绝. 2, 浏览器传给服务器端的日期格式字符串,服务器端理解不了,所以需要 ...
- centos7.4应用之KVM
最小安装系统: 参考博客:https://www.cnblogs.com/chenjiahe/p/5911965.html 辅助命令 yum install make bison flex autom ...
- September 13th 2017 Week 37th Wednesday
Whenever people agree with me, I always feel I must be wrong. 每次人们赞同我时,我都觉得自己一定错了. We can draw lesso ...
- python邮件处理
SMTP SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式.Python对SMTP支持有 ...