最近一个项目 需要用到jstree 这个jQuery插件,就研究了下,做目录树 菜单还是很强大的,下面对经常会用到几个用法做下说明。

1. 首先页面 引用 jquery.jstree

2. html :

  1. <div id="cate_tree" class="jstree fl">
  2. <ul>
  3. <li id="0" class="jstree-closed jstree-unchecked">
  4. <a href="#" class="jstree-clicked">
  5. <ins class="jstree-checkbox"> </ins>
  6. All Product
  7. </a>
  8. <ul style="">
  9. {foreach $categories as $cat}
  10. <li id="{$cat.id}" class="jstree-closed jstree-unchecked">
  11. <a href="#" class="jstree-clicked">
  12. <ins class="jstree-checkbox"> </ins>
  13. {$cat.name}
  14. </a>
  15. {if $cat.sub|@count > 0}
  16. <ul style="">
  17. {foreach $cat.sub as $subcat}
  18. <li id="{$subcat.id}" class="jstree-leaf jstree-unchecked">
  19. <a href="#" class="">
  20. <ins class="jstree-checkbox"> </ins>
  21. {$subcat.name}
  22. </a>
  23. </li>
  24. {/foreach}
  25. </ul>
  26. {/if}
  27. </li>
  28. {/foreach}
  29. </ul>
  30. </li>
  31. </ul>
  32. </div>

默认所有目录树打开不选中, 样式为

  1. class="jstree-closed jstree-unchecked">
  1. 默认打开目录树,样式为
    1. <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 主题路径
    2. $.jstree._themes = Www_URL_JS + 'jstree/themes/';
    3. $("#cate_tree").jstree({
    4. "plugins" : [ "themes", "html_data", "checkbox", "ui" ],
    5. "themes": {
    6. "theme": "classic",
    7. "dots": true,
    8. "icons": false
    9. }
    10. });</pre><br>
    11. <br>
    12. <pre></pre>
    13. <pre name="code" class="html">默认主题 是default,是文件夹样式,classic 是 + - 号的样式<pre></pre>
    14. <pre></pre>
    15. <pre></pre>
    16. <p></p>
    17. <p><br>
    18. </p>
    19. <pre></pre>
    20. <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 = [];
    21. $("#cate_tree .jstree-checked").each(function(){
    22. var $this = $(this);
    23. cate_ids.push($this.attr("id"));
    24. });</pre><br>
    25. <br>
    26. <pre></pre>
    27. <pre></pre>
    28. <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({
    29. "plugins" : [ "themes", "html_data", "checkbox", "ui" ],
    30. "themes": {
    31. "theme": "classic",
    32. "dots": true,
    33. "icons": false
    34. }
    35. });
    36. cate_js_tree.bind('loaded.jstree', function () {
    37. $("#cate_tree").find("li").each(function() {
    38. var $this = $(this);
    39. for(x in cate_ids) {
    40. if ($this.attr("id") == cate_ids[x]) {
    41. $("#cate_tree").jstree("check_node", $this);
    42. }
    43. }
    44. });
    45. });</pre><br>
    46. <br>
    47. <pre></pre>
    48. <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
    49. </pre>
    50. <p></p>
    51. <pre></pre>
    52. <pre></pre>
    53. <pre></pre>
    54. <pre></pre>
    55. <pre></pre>
    56. <pre></pre>
    57. <pre></pre>
    58. </pre></pre></pre></pre></pre></pre>

jquery jstree 插件的使用的更多相关文章

  1. 利用jstree插件轻松构建树应用

    最近完成了项目中的一个树状应用,第一次接触了jstree这个插件,总的来说它的官方文档还是比较详细的,但是在使用过程中还是出现了一些问题,下面我就来谈谈这款插件的使用和心得. 首先项目需要构建一棵树, ...

  2. 顶级jQuery树插件

    顶级jQuery树插件 顶级jQuery树插件 2013-03-05 17:20 139人阅读 评论(0) 收藏 举报 jsTree JsTree是一个基于jQuery的Tree控件.支持HTML.J ...

  3. 深入学习jQuery自定义插件

    原文地址:jQuery自定义插件学习 1.定义插件的方法 对象级别的插件扩展,即为jQuery类的实例增加方法, 调用:$(选择器).函数名(参数);      $(‘#id’).myPlugin(o ...

  4. [jQuery]jQuery DataTables插件自定义Ajax分页实现

    前言 昨天在博客园的博问上帮一位园友解决了一个问题,我觉得有必要记录一下,万一有人也遇上了呢. 问题描述 园友是做前端的,产品经理要求他使用jQuery DataTables插件显示一个列表,要实现分 ...

  5. 使用jQuery.form插件,实现完美的表单异步提交

    传送门:异步编程系列目录…… 时间真快,转眼一个月快结束了,一个月没写博客了!手开始生了,怎么开始呢…… 示例下载:使用jQuery.form插件,实现完美的表单异步提交.rar 月份的尾巴,今天的主 ...

  6. 为jQuery写插件

    很多场合,我们都会调用jQuery的插件去完成某个功能,比如slider. 如下图,做一个div,通过“$( "#slider" ).slider();”的方式直接将div变成sl ...

  7. bootstrap-简洁实用的jQuery手风琴插件

    前端 <html lang="zh"> <head> <meta charset="UTF-8"> <meta htt ...

  8. 推荐15款响应式的 jQuery Lightbox 插件

    利用现代 Web 技术,网络变得越来越轻巧与.模态框是突出展现内容的重要形式,能够让用户聚焦到重要的内容上去.在这个列表中,我们编制了15款响应式的 jQuery 灯箱库,这将有助于开发人员创建和设计 ...

  9. Chocolat.js – 响应式的 jQuery Lightbox 插件

    Chocolat.js 使您能够显示一个或多个图像在同一页面上.给用户展示一组图片缩略图,可以显示全页或块.Chocolat.js 可以很好地处理所有主要的浏览器.它在下面这些浏览器测试通过:IE7+ ...

随机推荐

  1. OpenCV基础篇之像素操作对照度调节

    程序及分析 /* * FileName : contrast.cpp * Author : xiahouzuoxin @163.com * Version : v1.0 * Date : Tue 29 ...

  2. CI 日志类

    开发ci的过程中,使用log能直观的看出代码运行到哪,还可设置代码查看数据接口的发送情况.日志类: <?php defined('BASEPATH') OR exit('No direct sc ...

  3. 【CV论文阅读】action recognition by dense trajectories

    密集轨迹的方法是通过在视频帧上密集地采样像素点并且在追踪,从而构造视频的局部描述子,最后对视频进行分类的方法依然是传统的SVM等方法. 生成密集轨迹: (1)从8个不同的空间尺度中采样,它们的尺度差因 ...

  4. 交换机tagged与untagged的关系深入探讨

    端口接收数据时: 如果端口是tagged方式,当数据包本身不包含VLAN的话,输入的数据包就加上该缺省vlan:如果数据包本身已经包含了VLAN,那么就不再添加. 如果是untagged方式,输入的数 ...

  5. 1.5 - 动态路由协议ISIS

    IS-IS 特征: 1:协议操作起来,比OSPF要简单 2:扩展性比OSPF要好,易于扩展 3:对IPv6有很好的支持 4:能够同时支持IP网络,和CLNS网络(OSI网络)(集成的IS-IS) 5: ...

  6. Test While You Sleep (and over Weekends)

    Test While You Sleep (and over Weekends) Rajith Attapattu RELAX. I am not referring to offshore deve ...

  7. LeetCode 8. String to Integer (atoi) (字符串到整数)

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  8. 从一个小demo开始,体验“API经济”的大魅力

    写在前面 “API经济”这个词是越来越火了,但是"API经济"具体指的是什么,相信很多人还没有个明确的认识.不过今天我可不打算长篇大论的去讲解一些概念,我们就以“电话号码归属地查询 ...

  9. FOBiz组合模糊查询

    List list= delegator.findList("Entity",condition , null, null, null, false);其中condition为:组 ...

  10. Python3基础复习

    目录 基本语法 运算符 输出格式 数据类型 数据结构 函数 面向对象 补充 异常 模块和包 文件 时间 线程和进程 基本语法 基本语法只列举与Java不一样的. 运算符 and, or而非 & ...