2012-08-10 72 views
1

我有一個jstree JQuery插件,我使用它的「複選框」插件。我需要以編程方式選擇複選框並禁用複選框,也是以編程方式。禁用JStree JQUery插件中的複選框

我該怎麼做?

https://groups.google.com/forum/?fromgroups#!topic/jstree/wLokkEg3eCY%5B1-25%5D這個我試過沒有結果。

我Jstree:

var myTree = $(tree).jstree({ 
    "json_data": { 
     "ajax": { 
      type: "POST", 
      async: true, 
      "url": urlTree, 
      // data: '{"longnames":"' + flag + '"}', 

      data: function (n) { 
       id = n.attr ? n.attr("id") : prefix + '0'; 
       reply = '{ id: "' + id + '"'; 
       // if (dataJSON.length > 0) { 
       //  reply = reply + ", " + dataJSON; 
       // } 
       reply += ', longnames: "' + flag + '"'; 
       // reply += ", prefix: "; 
       // reply += (mutateIds != 1) ? '' : '"' + prefix + '"'; 
       reply += "}"; 

       return reply 
      }, 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      cache: false, 
      success: function (msg) { 

       return msg.d.data; 
      }, 
      error: function() { 
       // process error of ajax 
       return false; 
      } 
     }, 
     // "xsl": "flat", 


    }, 
    "search": { 
     "show_only_matches": true, 
     "search_method": "jstree_contains" 
    }, 
    "types": { 
     "max_children": -2, 
     "max_depth": -2, 
     "default": { 
      "valid_children": ["default"], 
      "select_node": function (e) { 
       this.toggle_node(e); 
       return false; 
      } 
     }, 
     "disabled" : { 
        "check_node" : false, 
        "uncheck_node" : false 
       } 
    }, 
    "cookies": { 
     "save_opened": false 
    }, 
    "checkbox":{ 
     "override_ui": "true", 
     "real_checkboxes": "true" 
    }, 
    "plugins": pluginsToUse 
}) 
+0

你有沒有試過這兩個建議?像添加「defualt」下的功能?之後你只需要調用它們...然後在調用函數之後在控制檯中是否有任何js錯誤? – SamiSalami 2012-08-10 15:55:40

+0

是的,我做過了,基本上我添加了這樣的功能。我確實在代表菜單項的LI標籤中獲得了「rev = disabled」,但它沒有改變行爲。 – 2012-08-10 20:10:51

+1

你可以通過css隱藏它們嗎? – Radek 2012-08-10 21:27:10

回答

1

要檢查節點programmaticlly所有你需要做的是:

$('#tree').jstree('check_node','#id'); 

這裏#ID是節點的ID。