How to change Icon dynamically?

1,580 views
Skip to first unread message

praveen lobo

unread,
Apr 3, 2014, 3:09:01 AM4/3/14
to jst...@googlegroups.com
Below function runs when i click on the Context menu. I am setting the Icon but does not appear. Am i missing anything here?

function selectCurrentAndFutureChild(obj, treeInstance) {
    var postCompleteTree = jQuery.jstree.reference(treeInstance).get_json();
    var nodeID = obj.reference.context.attributes[1].value;
    var instance = $.jstree.reference(treeInstance);
    var node = instance.get_parent(nodeID);
    if (node == "#") {
        instance.select_node(nodeID);
        var i = 0, j = 0;
        while (i < postCompleteTree.length) {
            if (postCompleteTree[i].id.toString() == nodeID) {
                postCompleteTree[i].icon = "glyphicon glyphicon-ok-sign";
                instance.disable_node(nodeID);
                postCompleteTree[i].data.futureAndCurrent = true;
                while (j < postCompleteTree[i].children.length) {
                    var nodeID = postCompleteTree[i].children[j].id.toString();
                    var instance = $.jstree.reference(nodeID);
                    instance.disable_node(nodeID);
                    j++;
                }
            }
            i++;
        }
    }
    else
        instance.select_node(node);
}

Thank you in advance.

Ivan Bozhanov

unread,
Apr 3, 2014, 3:35:50 AM4/3/14
to jst...@googlegroups.com
Use: instance.set_icon(nodeID, "glyphicon glyphicon-ok-sign");

Best regards,
Ivan

praveen lobo

unread,
Apr 3, 2014, 3:45:28 AM4/3/14
to jst...@googlegroups.com
Dear Ivan,

I tried the solutions you provided, but still its not displaying.
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "jsTree" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/jstree/GCh1r1_NeT4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jstree+un...@googlegroups.com.
> To post to this group, send email to jst...@googlegroups.com.
> Visit this group at http://groups.google.com/group/jstree.
> For more options, visit https://groups.google.com/d/optout.



--
Regards,
Praveen Lobo

Ivan Bozhanov

unread,
Apr 3, 2014, 3:53:22 AM4/3/14
to jst...@googlegroups.com
Sorry, but to help you further I need a more clean code sample with all variables included - all I can tell you is that there is no problem with the set_icon function - see if you get any errors in the console.

best regards,
Ivan

praveen lobo

unread,
Apr 3, 2014, 5:34:35 AM4/3/14
to jst...@googlegroups.com
Hi Ivan,

If i check the code, Icon is added and when i debug i can see the new
icon added. But in the front end, image is not shown. Image does not
appear. But when i set it from the controller it appears.(MVC)


iconForFuture = "glyphicon glyphicon-ok-sign";
ActorGroupJsonModel actorGroupJsonModel = new ActorGroupJsonModel()
{
id = treeType + "Group" +
actorModel.ActorGroupId.ToString(),
parent = "#",
text = actorModel.ActorGroupName,
icon = iconForFuture,
state = stateObj,
data = dataObj
};

When i do this and load the tree, image appears.
>> > jstree+un...@googlegroups.com.
>> > To post to this group, send email to jst...@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/jstree.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Regards,
>> Praveen Lobo
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "jsTree" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/jstree/GCh1r1_NeT4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> jstree+un...@googlegroups.com.

Ivan Bozhanov

unread,
Apr 3, 2014, 7:05:08 AM4/3/14
to jst...@googlegroups.com
Can you provide a fiddle for this, sorry but the code you are providing does not help - if I run for example: $('#jstree1').jstree(true).set_icon('j1_5', 'glyphicon glyphicon-ok-sign'); on the jstree home page I can see the icon changing. I cannot reproduce the problem.

Best regards,
Ivan
>> > To post to this group, send email to jst...@googlegroups.com.
>> > Visit this group at http://groups.google.com/group/jstree.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
>> --
>> Regards,
>> Praveen Lobo
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "jsTree" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/jstree/GCh1r1_NeT4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
Reply all
Reply to author
Forward
0 new messages