jstree java_jsTree ajax使用方法

本文展示了如何使用jsTree库从外部JSON文件异步加载数据。通过jQuery的ajaxSetup禁用缓存,并配置jsTree的数据选项,包括指定数据类型为JSON,设置异步加载,并提供URL。同时,定义了加载提示文字、样式和回调函数,确保首次加载后不再使用静态数据。此外,还使用了插件实现右键菜单功能。
摘要由CSDN通过智能技术生成

1 html2 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">4 5 6 7 jsTree»Demos8 9 10 11 12 13 14 15 16 18 19 20 21 23 24 26 27 28 29 30 html,body{31 margin:0;32 padding:0;33 }34 35 body,td,th,pre,code,select,option,input,textarea{36 font-family:"Trebuchet MS", Sans-serif;37 font-size:10pt;38 }39 40 #container{41 width:800px;42 margin:10px auto;43 overflow:hidden;44 }45 46 .demo{47 height:200px;48 width:300px;49 float:left;50 margin:0;51 border:1px solid gray;52 font-family:Verdana;53 font-size:10px;54 background:white;55 overflow:auto;56 }57 58 .code{59 width:490px;60 float:right;61 margin:0 0 10px 0;62 border:1px solid gray;63 }64 65 pre{66 display:block;67 }68 69 .syntaxhighlighter{70 margin:0 0 0 0 !important;71 padding:0 !important;72 }73 74 75 76 77 Async JSON demo78 

Same as with the HTML datastore you can load data from a file.

79 80 varstat=[81 { attributes : {"id":"node_1"}, data :"Node 1"},82 { attributes : {"id":"node_2"}, data :"Node 2", state :"closed"},83 { attributes : {"id":"node_3"}, data :"Node 3", state :"closed"}84 ];85 $(function() {86 $.ajaxSetup({cache:false});//ajax调用不使用缓存87 $("#async_json_1").tree({88 data : {89 type :"json",90 async :true,91 opts : {92 async :true,93 method :"GET",94 url :"async_json_data.json"95 }96 },97 lang:{98 loading:"目录加载中……"//在用户等待数据渲染的时候给出的提示内容,默认为loading99 },100 ui:{101 theme_name:'classic'//设置样式102 },103 callback : {104 //Make sure static is not used once the tree has loaded for the first time105 onload :function(t) {106 t.settings.data.opts.static=false;107 },108 //n--节点,t是tree109 beforedata :function(n, t) {110 if(n==false)111 t.settings.data.opts.static=stat;112 else113 return{parent_Id/*参数名称*/: $(n).attr("id")||false}//AJAX调用参数传递114 }115 },116 //插件使用右键菜单支持自定义右键菜单117 plugins:{118 contextmenu:{}119 }120 121 });122 });123 124 125 126 127 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值