Problem with load dynamic data from JSON

Hello, I need to open dynamic items tree ID - 0, next ID - 1 and ID - 162.
ID - 0 is load and then firebug give me error. Sorry for my english, is not good and I ask You for help.

Firebug give something like this:

TypeError: b is null
...oad===0?a.openItem(a.G_node):(a.openItem(a.G_node),a._stepOpen(a))}else a.onXLE=...

dhtmlxtree_xw.js (row 25)

included js files

<script src="/dhtmlxTree/codebase/dhtmlxcommon.js"></script>
<script src="/dhtmlxTree/codebase/dhtmlxtree.js"></script>
<script src="/dhtmlxTree/codebase/ext/dhtmlxtree_ed.js"></script>
<script src="/dhtmlxDataProcessor/codebase/dhtmlxdataprocessor.js"></script>
<script src="/dhtmlxTree/codebase/ext/dhtmlxtree_json.js"></script>

<script src="/dhtmlxMenu/codebase/dhtmlxmenu.js"></script>
<script src="/dhtmlxMenu/codebase/ext/dhtmlxmenu_ext.js"></script>

<script  src="/dhtmlxTree/codebase/ext/dhtmlxtree_xw.js"></script>
<script  src="/dhtmlxTree/codebase/ext/dhtmlxtree_li.js"></script>

create object:

tree = new dhtmlXTreeObject("treeboxbox_tree", "100%", "100%", 0);
  tree.setSkin('dhx_skyblue');
  tree.setImagePath("/dhtmlxTree/codebase/imgs/csh_bluebooks/");
  tree.setXMLAutoLoading( config.employees.getTreeData );
  tree.setDataMode( "json" );
  tree.enableSmartXMLParsing( true );
  tree.enableCheckBoxes( false );
  tree.enableDragAndDrop( true );
  tree.enableThreeStateCheckboxes( true );
  //tree.loadJSON(config.employees.getTreeData + '?id=0');
  tree.enableDynamicLoading = true;
  tree.setXMLAutoLoadingBehaviour("id");
  tree.openItemsDynamic('0,1,162', true);
  tree.setOnRightClickHandler( rightClick );
  tree.attachEvent( "onBeforeContextMenu", onBeforeOpen ); //przed otwarciem menu
  tree.enableContextMenu( menu ); //tree + menu

Item data when i open tree node by myself is like this:

  • 1
{"id":0,"item":[{"id":1,"text":"something","child":1,"im0":"something.gif","im1":"something.gif","im2":"something.gif"}]}
  • 2
{"id":1,"item":[{"id":162,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":true},{"id":163,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":false},{"id":164,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":false},{"id":165,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":false},{"id":166,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":false},{"id":167,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":true}]}
  • 3
{"id":162,"item":[{"id":177,"text":"something","im0":"something.gif","im1":"something.gif","im2":"something.gif","child":true}]}

I used v.3.5 build 120822 professional

Hello
It seems to me, that you try to load 162th item, which is not exist, because you are using tree.enableSmartXMLParsing( true );
You need to load it, and then - open.

ok
I don’t know it is right but in this case I try to load one level and then open branch in loop but it won’t work

is another way to open this tree programilly when enableSmartXMLParsing is true?

Oh, sorry, i misled you…
Could you attach the whole tree structure to reproduthe the issue?

Hello r.av,

I’m using the same dhtmlxtree package and version.
I’m also trying to open dynamically a tree from JSON data using openItemsDynamic().
In my case, i don’t have the same error as you, but only the first element id is opened correctly, no error message…
–> tree.openItemsDynamic(“12,72,622”,true) only loads children of id12 (of course, my ids are unique). manual opening works fine.

I was also using enableSmartXMLParsing(true), but nothing changes if I remove it.

Is your “config.employees.getTreeData” a javascript function or a string containing a file path ?

now I have no way to attach it, I do it tomorrow morning

config.employees.getTreeData is a string

Guys!
Could you provide a full code and tree structure? Interesting case, I want to test it myself. :slight_smile:

Hi MCD,

I was able to reproduce the issue in a simple test case.
Please find full code in this attached zip file.
Note that the dhtmlx folder is not included, since i don’t think the license allows me to share it (i’m using PRO version).

My goal : Opens items and children automatically until I find desired element (children are loaded dynamically using ajax and JSON)
My issue : openItemsDynamic() open the first element only, as if following ids were not provided
Maybe it’s not an issue but a misunderstanding on this functionality : it opens elements only if they are existing, looks like newly created elements are not found.

Thank you for your investigation.
ddimanche_sample.zip (80 KB)

r.av,
You did not load a root level. Try the following:

tree.setXMLAutoLoading( config.employees.getTreeData ); tree.loadJSON(config.employees.getTreeData + '?id=0',function(){ tree.openItemsDynamic('0,1,162', true); });

ddimanche,

openItemsDynamic works with dhtmlx, it sets loading end handler that opens next item in list. And you are using jQuery. Therefore, you need to use custom methods to handle ajax loading. I have modified the sample that you attached and included the possible solution there.
index.zip (1.06 KB)

Hi Alexandra,

Your code sample is working fine and I understand it : you’re creating your own openItemsDynamic routine but adapted with jQuery, smart:)

Thank you very much!