Note that there are some explanatory texts on larger screens.

plurals
  1. POjsTree not creating node of an specific type
    text
    copied!<p>I've followed the code fragment in the last example of <a href="http://www.jstree.com/demo/types" rel="nofollow">http://www.jstree.com/demo/types</a> to create a node of a given type and I've got no idea why it doesn't work.</p> <p>HTML Fragment:</p> <pre><code> &lt;form&gt; &lt;button id="buttonAddMenu" type="button"&gt;Créer Menu&lt;/button&gt; &lt;button id="buttonAddParameter" type="button"&gt;Créer Paramètre&lt;/button&gt; &lt;button id="buttonRename" type="button"&gt;Renomer&lt;/button&gt; &lt;button id="buttonRemove" type="button"&gt;Supprimer&lt;/button&gt; &lt;button id="buttonShowData" type="button"&gt;Show Data&lt;/button&gt; &lt;/form&gt; &lt;div id="checkListParams"&gt; &lt;ul&gt; &lt;li id="new001"&gt;&lt;a href="#"&gt;Root menu 1&lt;/a&gt;&lt;/li&gt; &lt;li id="new002"&gt;&lt;a href="#"&gt;Root menu 2&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Menu 2.1&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Menu 2.2&lt;/a&gt; &lt;ul&gt; &lt;li rel="parameter"&gt;&lt;a href="#"&gt;Parameter A&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; </code></pre> <p>Javascript:</p> <pre><code>$(document).ready(function() { //================ //Configuring tree //================ $("#checkListParams").jstree({ "ui" : { "select_limit": 1 }, "contextmenu" : { "select_node": true }, "hotkeys" : { "del": false //disable deleting nodes only via DEL key }, "types" : { "valid_children" : [ "default" ], "use_data" : true, "types" : { "default" : { "valid_children" : [ "all" ] }, "parameter" : { "icon" : { "image" : "site/media/img/icons/checklist_parameter.png" }, "valid_children" : [ "none" ], "create_node": false } } }, "core" : { "initially_open" : [ "all" ] }, "plugins" : [ "themes", "html_data", "xml_data", "ui", "crrm", "dnd", "contextmenu", "hotkeys", "types" ] }); //========================== //Configuring button actions //========================== $("#buttonAddMenu").click(function() { $("#checkListParams").jstree("create"); }); $("#buttonAddParameter").click(function() { //$("#checkListParams").jstree("create", null, "inside"); //works! $("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } }); }); $("#buttonRemove").click(function() { $("#checkListParams").jstree("remove"); }) $("#buttonRename").click(function() { $("#checkListParams").jstree("rename"); }) $("#buttonShowData").click(function() { var nodes = $("#checkListParams").jstree("get_xml", { "li_attr" : [ "id" , "class", "rel" ] }); alert(nodes); }) }); </code></pre> <p>The line</p> <p>$("#checkListParams").jstree("create", null, "inside", { "attr" : { "rel" : "parameter" } });</p> <p>is not working. I've tried to change the type to "default", without success... Also, I've got no error messages (I don't like not getting error messages when things don't run).</p> <p>Thank you in advance.</p> <p><strong>UPDATE</strong></p> <p>Solved using instructions in <a href="http://osdir.com/ml/jstree/2011-04/msg00126.html" rel="nofollow">http://osdir.com/ml/jstree/2011-04/msg00126.html</a> . Explicitly listing all valid children (instead of using "all") solved the problem. </p> <p>I'll check whether a similar bug is filed in jsTree issues pages tomorrow, maybe adding a new one.</p> <p>Thanks anyway.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload