Bootstrap Tree View从前端到后台的例子
来源:互联网 发布:python做时间序列分析 编辑:程序博客网 时间:2024/05/20 10:20
Bootstrap Tree View 是一个简单而优雅的Bootstrap树形视图解决方案。
可以访问作者的 GitHub页面 了解其用法及更多信息。
https://github.com/jonmiles/bootstrap-treeview
效果图
//新建一个实体类public class NewTree implements java.io.Serializable { private String id; private String text; private List<NewTree> nodes = new ArrayList<NewTree>(); //下面是getset方法...
//JSONArray.fromObject()引用的包为net.sf.json.JSONArray;@Controllerpublic class TestController{ @Resource(name="demoService") private IDemoService demoService; /** * 递归获取整棵树的json */ @ResponseBody @RequestMapping(value="/testTree.do",produces={"application/json;charset=utf8"}) public String testCateTree() throws Exception { List<NewTree> cateList = new ArrayList<NewTree>(); List<NewTree> demos = demoService.getInfosByParentId("0"); //构建 Data Structure json对象 JSONArray jsonArray = JSONArray.fromObject(demos); String jsonString = jsonArray.toString().replace(",\"nodes\":[]", ""); return jsonString; }}
/** * 递归获取整棵树的json * @param string * @return */ @Override public List<NewTree> getInfosByParentId(String pid) {//最顶层parentI //st第一次数据库拿到最顶层的数据,根据顶层parentID获取下面的数据 //allST数据库获取所有的数据对象 List<NewTree> topCateList = new ArrayList<NewTree>(); NewTree twoCate = new NewTree("0","最顶层的标题",new ArrayList<NewTree>()); twoCate.setNodes(recursion(pid,st,allST)); topCateList.add(twoCate); return topCateList; } public List<NewTree> recursion(String pid,List<数据库对象> st1,List<数据库对象> allST) { List<NewTree> cateList = new ArrayList<NewTree>(); OUTTER:for(数据库对象 st : st1){ INNER:for(int i = 0;i< allST.size();i++){ if(st.getId().equals(allST.get(i).getParentId())){ NewTree cate = new NewTree(st.getId(),st.getName(),new ArrayList<NewTree>()); List<NewTree> twoCateList = recursion(null,getInfos(st.getId()),allST); cate.setNodes(twoCateList); cateList.add(cate); break INNER; }else if((i+1)==allST.size()){ NewTree cate = new NewTree(st.getId(),st.getName()); cateList.add(cate); } } } return cateList; }
下面是前端代码
//刷新模块树var referchModule = function () { //发送异步请求加载所有的模块信息 $.ajax({ type:"post", dataType:"json", url:getRootPath_web()+"/testTree.do",//getRootPath_web()获取根目录地址的方法,另一篇博客里面有 success:function(defaultData){ // defaultData = JSON.parse(defaultData); $('#tree').treeview({ data: defaultData,//数据源参数 color: "#428bca", showBorder: false, // levels:2, onNodeSelected: function(event, node) { alert(node.id+"前面是id,后面是名字"+node.text);//这里拿到id和name,就可以通过函数跳转触发点击事件 }, onNodeUnselected: function (event, node) { } }); },error:function(){ alert("加载树异常!"); } })}
html代码
<div id="tree"></div>
如果该文章中有哪些不足或者改进,希望您能留下评论告知一声。
阅读全文
2 0
- Bootstrap Tree View从前端到后台的例子
- 从前端页面到后台的流程
- Bootstrap Tree View API
- bootstrap table + spring + springmvc + mybatis 实现从前端到后端的表格分页
- 上传文件到服务器例子,包括前端后台一整套
- 【ssh】——Struts2从前端传值到后台的三种方法(从属性到ModelDriven)
- 从前端到后台,开发一个完整功能的小程序
- 一个项目流程(从前端到后台)服务器相关
- vue2+webpack+express 简单入门:从前端到后台
- kindEditer富文本编辑器从前端到后台完整经验
- Bootstrap Tree View,简单而优雅的树结构组件
- Bootstrap Tree View,简单而优雅的树结构组件
- bootstrap开发,实现前端后台模块分离
- 从后台到webshell的一点思路
- 聊聊JS语言是如何从前端移到后台的
- 前端ajax获取从后台传回的数据
- bootStrap ace tree例子 JAVA版本
- bootStrap ace tree例子 JAVA版本
- MaBatis框架
- 程序员笔试题之字符串(1)
- 递归实现打印12345---简单理解递归
- 提高Eclipse的速度,去掉对于工程的 Validatioan
- Java学习笔记 --- 反射机制
- Bootstrap Tree View从前端到后台的例子
- 零基础学习软件测试从懵逼到吊炸天之基础与进阶篇
- Pixy(Cmucam5)通过SPI与Arduino通信
- 记事本DEMO
- Android APK反编译之路
- Android使用Fiddler模拟弱网络环境测试
- Mac安装apache24和PHP多版本切换MongoDB和MYSQL
- 磁盘阵列(raid)
- react-create-app打包过程遇到的问题