2011-09-27 91 views
0

我正在使用JsTree 1.0,並且無法使用複選框插件預先檢查複選框。Jstree - 預檢覆選框

這裏是我的全碼:

$(".tree").bind("loaded.jstree", function (event, data) { 
       $('.tree li.checked').each(function() { 
        $(this).prop("checked", true); 
       }) 
      }).jstree({ 
       "core" : { "animation" : 0}, 
       "json_data" : { 
        "ajax" : { 
         "url" : "/admin/posts/get_taxonomy_tree", 
         "data" : function (n) { 
          return { id : n.attr ? n.attr("id") : 0 }; 
         } 
        }, 
        "progressive_render" : true 
       }, 
       "checkbox" : { 
        "real_checkboxes" : true, 
        "real_checkboxes_names" : function(n){ 
         return [("term_taxonomy_id_" + (n[0].id || Math.ceil(Math.random() * 10000))), 1]; 
        } 
        }, 
       "themes" : { 
        "url" : "/assets/admin/js/jstree/themes/default/style.css", 
        "icons": false 
       }, 
       "plugins" : [ "themes", "json_data", "checkbox" ] 
      }).delegate("a", "click", function (event, data) { event.preventDefault(); }); 

我已經添加了綁定事件loading.jstree,但這是不正確的 - 不工作。

任何想法?謝謝!

編輯:

解決辦法是添加類jstree-checked,默認將預勾選

+1

所以你想要的所有複選框最初有類「檢查」的權利? – Evan

+0

我可以應用這個類,它目前不在json中返回。 – dzm

回答

1

確保添加了「檢查」類,因爲它使用前檢查對負載箱=)

+0

當然爲什麼不...足夠接近:) – dzm

5

解決方案是增加「jstree覈對」,這將默認類前檢查盒子

1

下面的代碼可以解決您的問題。

$('.tree').jstree("check_all");