How to check a checkbox in a jsTree (JavaScript) -


i'm using jstree , having problem preset checkboxes via data stored in cookie.

i'm able store clicked checkboxes in cookie not know how check checkboxes data saved within cookie.

maybe problem way create jstree because none of samples tried work.

to give code understand did have @ submit function. iterates on of checked checkboxes , creates array of id's id field stored in metadata way , maybe that's reason why not work way expected.

<script>   $(document).ready(function() {     $("#treeviewdiv").jstree({       "core": { // core options go here         "multiple": true, // no multiselection         "themes": {           "dots": false // no connecting dots between dots         }       },        "json_data": {         "data": [{           "data": "options",           "metadata": {             "group": "1"           },           "children": [{             "data": "option 1",             "metadata": {               "id": "1"             }           }, {             "data": "option 2",             "metadata": {               "id": "2"             }           }, {             "data": "sub option",             "children": [{               "data": "option 3",               "metadata": {                 "id": "3"               }             }, {               "data": "option 4",               "metadata": {                 "id": "4"               }             }, {               "data": "option 5",               "metadata": {                 "id": "5"               }             }],             "metadata": {               "group": "master control"             }           }]         }]       },       "plugins": ["themes", "json_data", "ui", "checkbox"]     }).bind("select_node.jstree", function(e, data) {       if (jquery.data(data.rslt.obj[0], "href")) {         //alert("go on..");        } else {         //alert("no href defined element");       }     })   }); </script> 

i'm able retrieve checked nodes , create list way below , guess there methode loop on of tree objects, identify them id , check them tried , found @ web did not help.

function submitme() {   var checked_ids = [];   var checked_ids_meta = [];   var group;    checked_ids.push("( null ");    $("#treeviewdiv").jstree("get_checked", null, true).each(function(i, e) {     if ($(this).data("group") + "" != "undefined") {       group = $(this).data("group") + "";     }     if ($(this).data("id") + "" != "undefined") {       checked_ids.push($(this).data("id"));     }   });    checked_ids.push(" null )");    document.getelementbyid("jsfields").value = checked_ids.join(",");   alert(document.getelementbyid("jsfields").value);   return true; } 

selection stored within html in

<input name="jsfields" id="jsfields" size=80 maxlength=256 > 

what want implement reverse function check checkboxes same id.

one point figured out now:

so far see issue add id li tag using json.

i tried else:

<div id="oldfellow"> <ul>  <li id="node_1" ><a>node 1</a>       <ul>         <li id="leaf_1" ><a>leaf 1</a></li>         <li id="leaf_2" ><a>leaf 2</a></li>         <li id="leaf_3" ><a>leaf 3</a></li>       </ul>     </li>       </ul> </li> </ul> </div> <input type="hidden" name="jsfields" id="jsfields" value="" />   <script>    $("#oldfellow").jstree(   {    "plugins"  : [ "html_data", "types", "themes" , "checkbox" ]   });    $.jstree._reference("#oldfellow").check_node('li#leaf_1');   </script>  

code above pre-select checkbox within jstree.

so question is: how add id html li tag using json used in sample?

i fixed myself. it's easy.

{               "data": "option 3",               "attr": {"id":"3"},               "metadata": {"id": "3"} } 

it's required add "attr" object. in real code used in program (not shown here) wrote "attribute" , not "attr".

so have simple example on how use jstree checkboxes.

regards old fellow

by way: create issue plus useful solution not of programmers can do.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -