Setting "rel" attribute when adding JSON child node

1,383 views
Skip to first unread message

Patrice

unread,
Jan 26, 2011, 9:16:50 AM1/26/11
to jsTree
Hi all,

I try to add a child node and specify its "rel" Html attribute by this
way :

$("#demo_2").jstree("create", $("#essai\\.id"), "inside",
{ "data" : "reference","attr" : { "rel" :"ref"},},
function() { alert("added"); }, true);

If I change "rel" attr by "id" attr the child node is added (works
well), but when I specify the "rel" attribute its doesn't work and I
haven't error message.

Do I do something wrong ?


Regards

Patrice

mvwd

unread,
Jan 26, 2011, 10:25:36 AM1/26/11
to jsTree
...no, this call seems correct. Just one little thing: there's a
unnecessary comma, right after { "rel" :"ref"}, <==

This works for me and alerts the created 'rel':

$("#jstree-id").jstree("create", $("#nodes-id"), "inside", { "data" :
"reference", "attr" : { "id": "wat", "rel" :"ref"} }, function(data)
{ alert("added with rel:"+data.attr('rel')); }, true);

mvwd.

Patrice

unread,
Jan 26, 2011, 11:37:46 AM1/26/11
to jsTree
Thanks for this replay.
Well, doesn't works for me.... I used jstree r233

My full process is the following (call by contextmenu)
The followinf steps are in same function.

1° Create a node (working well) (#prj_name").val()=="essai" )

$("#Mtree").jstree("create", $("#Mtree"), "after",
{ "data" : $("#prj_name").val(), "attr" : { "id" : $("#prj_name").val()
+".id","rel" :"prjoject" }},
function() { alert("project folder added"); }, true)

2° Create a Child node to the previous created node (rel attr not
working...)

$("#Mtree").jstree("create", $("#essai\\.id"), "inside",
{ "data" : "reference","attr" : { "rel" :"ref"}},
function() { alert("Child added"); }, true);


I need to set "rel" attr, because I defined properties via this
attribute.
:(
(sorry for my English...)

Patrice

mvwd

unread,
Jan 26, 2011, 12:04:42 PM1/26/11
to jsTree
...if i understood you right the first call works, but the second one
fails!?

I think that's because you're using the dot (.) in the id. jQuery-Docu
sais to escape the dot with two backslashes (\\.), as you did
correctly in your example. ...i truly believe, the docu's wrong. The
W3C-document (linked from jQuery-docu) tells, just to escape with one
backslash (\.). And this will work! Give it a try!

=>
$("#Mtree").jstree("create", $("#essai\.id"), "inside",
{ "data" : "reference","attr" : { "rel" :"ref"}},
function() { alert("Child added"); }, true);


Markus.

Patrice

unread,
Jan 27, 2011, 4:32:19 AM1/27/11
to jsTree
Thanks Markus for reply.

You right, The first call works and the second fails.
I have try to escape with one backslash as you propose but It's still
not working for me and no error displayed in error log(firefox)
:(


I have try this way that working but is not very nice...

$("#demo_2").jstree("create", $("#essai\\.id"), 1,
{ "data" : "reference","attr" : { "id" :"ref"}},
function() { alert("added"); }, true);
$("#ref").attr("rel","ref");


Patrice

mvwd

unread,
Jan 28, 2011, 4:21:31 AM1/28/11
to jsTree
I think you should check first, as the first node was correctly added,
what's it's ID and REL:

$("#Mtree").jstree("create", $("#Mtree"), "after",
{"data" : $("#prj_name").val(),
"attr" : { "id" : $("#prj_name").val()
+".id","rel" :"prjoject" }},
function(data) {
alert("added! ID:"+data.attr('id')+" REL:"+data.attr('rel'));
}, true);

And then you can try to create your second node by accessing the
alerted ID.

AND: I strongly recommend NOT using any meta-characters! If you want
some kind of namespace-seperator in your ID's, use hyphen (-) or
undescore (_).

Again: your code is working for me. Maybe the problem lays somewhere
else in your code. If you don't get it working post (or send per
eMail) the full code you'r using.

Markus.

Patrice

unread,
Feb 1, 2011, 10:37:33 AM2/1/11
to jsTree
Thanks for reply Markus,

I have following your recommendations about ID's (I use underscore). I
have correct my code too for a others reasons, and now all works.
Thanks again for your help.

Patrice
Reply all
Reply to author
Forward
0 new messages