jquery jstree 插件的使用
2024-09-07 09:02:16
最近一个项目 需要用到jstree 这个jQuery插件,就研究了下,做目录树 菜单还是很强大的,下面对经常会用到几个用法做下说明。
1. 首先页面 引用 jquery.jstree
2. html :
- <div id="cate_tree" class="jstree fl">
- <ul>
- <li id="0" class="jstree-closed jstree-unchecked">
- <a href="#" class="jstree-clicked">
- <ins class="jstree-checkbox"> </ins>
- All Product
- </a>
- <ul style="">
- {foreach $categories as $cat}
- <li id="{$cat.id}" class="jstree-closed jstree-unchecked">
- <a href="#" class="jstree-clicked">
- <ins class="jstree-checkbox"> </ins>
- {$cat.name}
- </a>
- {if $cat.sub|@count > 0}
- <ul style="">
- {foreach $cat.sub as $subcat}
- <li id="{$subcat.id}" class="jstree-leaf jstree-unchecked">
- <a href="#" class="">
- <ins class="jstree-checkbox"> </ins>
- {$subcat.name}
- </a>
- </li>
- {/foreach}
- </ul>
- {/if}
- </li>
- {/foreach}
- </ul>
- </li>
- </ul>
- </div>
默认所有目录树打开不选中, 样式为
- class="jstree-closed jstree-unchecked">
- 默认打开目录树,样式为
- <pre name="code" class="html">class="jstree-open jstree-unchecked"></pre><pre name="code" class="html"></pre><pre name="code" class="html">默认需要全选,样式尝试</pre><pre name="code" class="html"><pre name="code" class="html">class="jstree-open jstree-checked"></pre><pre name="code" class="html"></pre><pre name="code" class="html">3. js 加载该目录树</pre><pre name="code" class="html"><pre name="code" class="javascript"></pre><pre name="code" class="javascript">// 设置jstree 主题路径
- $.jstree._themes = Www_URL_JS + 'jstree/themes/';
- $("#cate_tree").jstree({
- "plugins" : [ "themes", "html_data", "checkbox", "ui" ],
- "themes": {
- "theme": "classic",
- "dots": true,
- "icons": false
- }
- });</pre><br>
- <br>
- <pre></pre>
- <pre name="code" class="html">默认主题 是default,是文件夹样式,classic 是 + - 号的样式<pre></pre>
- <pre></pre>
- <pre></pre>
- <p></p>
- <p><br>
- </p>
- <pre></pre>
- <pre name="code" class="html">4. 获取选中的值</pre><pre name="code" class="html"><pre name="code" class="javascript"></pre><pre name="code" class="javascript">var cate_ids = [];
- $("#cate_tree .jstree-checked").each(function(){
- var $this = $(this);
- cate_ids.push($this.attr("id"));
- });</pre><br>
- <br>
- <pre></pre>
- <pre></pre>
- <pre name="code" class="html"></pre><pre></pre><pre name="code" class="html"></pre><pre name="code" class="html">5. 设置给定的值为选中状态</pre><pre name="code" class="html"><pre name="code" class="javascript"></pre><pre name="code" class="javascript">var cate_js_tree = $("#cate_tree").jstree({
- "plugins" : [ "themes", "html_data", "checkbox", "ui" ],
- "themes": {
- "theme": "classic",
- "dots": true,
- "icons": false
- }
- });
- cate_js_tree.bind('loaded.jstree', function () {
- $("#cate_tree").find("li").each(function() {
- var $this = $(this);
- for(x in cate_ids) {
- if ($this.attr("id") == cate_ids[x]) {
- $("#cate_tree").jstree("check_node", $this);
- }
- }
- });
- });</pre><br>
- <br>
- <pre></pre>
- <pre name="code" class="html">6. 如果还有不太明白的,可以访问官网查询,嘿嘿……<pre></pre><pre name="code" class="html">附上这个地址,本人觉得很不错,哈哈</pre><pre name="code" class="html">http://www.jstree.com/documentation/checkbox
- </pre>
- <p></p>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- </pre></pre></pre></pre></pre></pre>
最新文章
- Javascript数值转换(string,int,json)
- MSSQ调优所需用的语句
- webpack详细配置讲解
- 【WP8.1开发】选择与搜索联系人
- Eclipse使用多个Console
- Ztree实现带checkBox的下拉框
- c 深度剖析 1
- js中的数组Array定义与sort方法使用示例
- Java学习笔记--String StringBuffer StringBuilder
- C语言--位运算符
- 设计模式——模板模式(C++实现)
- Bookmarkable Pages
- android 开发之 ListView 与Adapter 应用实践
- HDU6280 From Tree to Graph
- CCF关于NOIP复赛网络申诉问题的公告
- bzoj 1095 括号序列求两点距离
- webuploader.js
- opencv中imread第二个参数的意义
- 没加载redis类,却可以实例化redis
- LinkedIn实时低延迟数据抓取系统Databus开源
热门文章
- [bzoj 1042][HAOI2008]硬币购物(用容斥原理弄背包)
- Java中DAO/DTO/PO/VO/BO/QO/POJO
- mysql bin-log 设置
- gradle: 修改gradle-xx-bin.zip下载地址
- Jupyter Notebook: 解决build docker-stacks时conda太慢的问题
- gogs: 如何恢复repository
- Swift具体解释之六----------------枚举、结构体、类
- HDU 1853 Cyclic Tour(最小费用最大流)
- UITextView获取光标位置
- ASP.NET无法检测IE10浏览器,导致无法登录