jQuery UI Widgets Forums Navigation Tree Set item context

This topic contains 3 replies, has 2 voices, and was last updated by  Dimitar 12 years, 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • Set item context #15446

    stonezhong
    Member

    Hi,

    I am creating tree using source (javascript array for items). I have a “select” event handler, however, in order to handle the event, I need to extra per-item related context, is there an way to associate the item (in source when initializing jqxTree) to the actually item created by the jqxTree?

    I tried to set “value” in item and I can see it gets populated into the jqx tree item, but “value” can only be string, if I set the “value” to an object, the item.value I got is “[Object Object]”

    $(‘#jqxTree’).jqxTree({ source: items, height: ‘300px’, width: ‘300px’ });
    $(‘#jqxTree’).bind(“select”, function(event) {
    var args = event.args;
    var item = $(‘#jqxTree’).jqxTree(‘getItem’, args.element);

    Thanks,
    Stone

    Set item context #15459

    Dimitar
    Participant

    Hello Stone,

    It is possible for value to be an object, you just have to access its properties, e.g. item.value.firstproperty.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Set item context #15519

    stonezhong
    Member

    Hi Dimitar,

    Thank you for the reply.

    Here is my code:

    When I click on “foo”, I expect to see “Object”, I saw “string” instead.

    Thanks,
    Stone

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fx>
    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <link rel="stylesheet" href="jqwidgets/styles/jqx.base.css" type="text/css" />
    <script type="text/javascript" src="scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxcore.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxbuttons.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxscrollbar.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxpanel.js"></script>
    <script type="text/javascript" src="jqwidgets/jqxtree.js"></script>
    <script type="text/javascript">
    $(function() {
    var items = [
    {expanded: false, label: "foo"},
    {expanded: false, label: "bar"}
    ];
    items[0].value = items[0];
    items[1].value = items[1];
    $('#jqxTree').jqxTree({ source: items, height: '300px', width: '300px' });
    $('#jqxTree').bind("select", function(event) {
    var args = event.args;
    var item = $('#jqxTree').jqxTree('getItem', args.element);
    alert(typeof(item.value));
    });
    });
    </script>
    </head>
    <body>
    <div id='jqxTree'></div>
    </body>
    </html>
    Set item context #15531

    Dimitar
    Participant

    Hi stonezhong,

    Thank you for your feedback. We were able to reproduce the reported issue and have created a work item on the matter.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.