jstree使用【一】初次使用
2016-07-18 10:15
405 查看
第一步 引入 需要本地引入的可去官方地址下载源码
1.style.min.css
2.jquery.min.js
3.jstree.min.js
第二步在需要加载jsTree的Html位置处加入
第三步写jstree的调用方法
这是一颗异步加载的车辆树,
core.data.url:加载时获取数据的地址
core.data.dataType:获取数据的类型
core.data:异步加载结点数据时,需要向后端接口请求的数据时,所需要传给后端的参数。
jstree支持返回接口数据的格式有两种
第一种:嵌套数据的形式
第二种 指定父id的形式。个人更喜欢使用第二种。值得注意的是第二种形式,必须指定父节点,当第一级为更节点时得指定他的父结点为“#”。
1.style.min.css
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
2.jquery.min.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
3.jstree.min.js
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
第二步在需要加载jsTree的Html位置处加入
<div id="jstree_vehicle"></div>
第三步写jstree的调用方法
function treeInit(data) { $('#jstree_vehicle').jstree({ 'core': { 'data': { 'url': COMMON.fenbiaoPath + "singleVehicleTrack.queryEntVehicleGroupVehicleTreeInfo.action", 'dataType': "json", 'data': function (node) { return {'vehicleMaster': node.id, 'index': node.type, 'tokenStr': COMMON.token}; } } } }) }
这是一颗异步加载的车辆树,
core.data.url:加载时获取数据的地址
core.data.dataType:获取数据的类型
core.data:异步加载结点数据时,需要向后端接口请求的数据时,所需要传给后端的参数。
jstree支持返回接口数据的格式有两种
第一种:嵌套数据的形式
{ id : "string" // will be autogenera 4000 ted if omitted text : "string" // node text icon : "string" // string for custom state : { opened : boolean // is the node open disabled : boolean // is the node disabled selected : boolean // is the node selected }, children : [] // array of strings or objects li_attr : {} // attributes for the generated LI node a_attr : {} // attributes for the generated A node }
第二种 指定父id的形式。个人更喜欢使用第二种。值得注意的是第二种形式,必须指定父节点,当第一级为更节点时得指定他的父结点为“#”。
{ id : "string" // required parent : "string" // required text : "string" // node text icon : "string" // string for custom state : { opened : boolean // is the node open disabled : boolean // is the node disabled selected : boolean // is the node selected }, li_attr : {} // attributes for the generated LI node a_attr : {} // attributes for the generated A node }
相关文章推荐
- HTML文档插入JS代码的几种方法
- HTML文档插入JS代码的几种方法
- ExtJS4-布局系统详解
- Guzzle Unable to parse JSON data: JSON_ERROR_SYNTAX - Syntax error, malformed JSON
- JS判断输入的数值不能为小数
- Javascript之Dom学习
- 15位和18位身份证JS校验的简单实例
- js对字符串加密,解密
- ExtJS4-Ext.Direct
- JSP常用跳转方式
- js里对日期格式化。
- js 中关于立即执行函数的个人理解
- js方法进行邮箱验证代码,完美运行 正则表达式
- WEB开发者必备的7个JavaScript函数
- TDBXJSONStream(BERLIN新增)的使用
- 全面了解javascript中的错误处理机制
- JS动态改变form表单里的action值属性的方法
- ExtJS-服务器代理
- js中变量类型判断
- iOS开发-javaScript交互