Cannot read property 'id' of null with jsTree 3.0.8

2,032 views
Skip to first unread message

Anton Titkov

unread,
Oct 26, 2014, 9:13:37 AM10/26/14
to jst...@googlegroups.com
Hello, Dear Ivan!

Firstly, many thanks for your plugin!

I am newbie in JS. I am trying to use jsTree with json and ajax.

$("#tree-1").jstree({
                        "themes" : { "theme" : "default", "icons" : true},
                        "plugins" : ["themes"],
                        "core" : {
                        "data" : {
                        "url" : function(node){
                        return "docsets.json?project_id=1";
                        },
                        "data" : function(node){
                        return { 'id' : node.id };
                        }
                        },
                        "check_callback" : true
                        }
              } // i've cut insufficient code


I see a json request in chrome for .....&id=# (actualy in encoded form ....&id=%23) which returns following result:

[{"id":"root_42","parent":"#","text":"Structure","state":{"opened":true},"children":[{"id":"1","parent":"root_42","text":"a new docset","state":{"opened":true}}]}]

but the tree still showing the loading state and i see error in Chrome:

Uncaught TypeError: Cannot read property 'id' of undefined

self.onmessage = function (data, undefined) {
					if(data.data) { data = data.data; }
					var dat = data.dat,
						par = data.par,
						chd = [],
						dpc = [],
						add = [],
						df = data.df,
						t_id = data.t_id,
						t_cnt = data.t_cnt,
						m = data.m,
						p = m[par],
						sel = data.sel,
						tmp, i, j, rslt,
						parse_flat = function (d, p, ps) {
							if(!ps) { ps = []; }
							else { ps = ps.concat(); }
							if(p) { ps.unshift(p); }
	the error occurs here --->>>>>                  var tid = d.id.toString(),
								i, j, c, e,
								tmp = {
									id			: tid,
									text		: d.text || '',
                                                       ..........



I understand that is something wrong with passing 'children' through the code, but i compare the passed json with the examples on the site www.jstree.com and i can't see mistakes.

Please, could you check what's wrong. More thanks!

Ivan Bozhanov

unread,
Oct 26, 2014, 11:36:57 AM10/26/14
to jst...@googlegroups.com
Either use the flat format (the one with the parent property), or the nested format (the one with the children property), do not mix them both.

Best regards,
Ivan

Anton Titkov

unread,
Oct 26, 2014, 2:57:03 PM10/26/14
to jst...@googlegroups.com
Dear Ivan, 
i see that in nested format 'id' and 'parent' should be omitted.
Thanks for clarifying!
BR

воскресенье, 26 октября 2014 г., 17:36:57 UTC+2 пользователь Ivan Bozhanov написал:

Ivan Bozhanov

unread,
Oct 26, 2014, 5:21:48 PM10/26/14
to jst...@googlegroups.com
Hi,

Only parent, ID should be there if you want to set it (although it is not mandatory - jstree will generate IDs if you do not supply them).

Best regards,
Ivan
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages