2012-08-10 58 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。