Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts

  • Rene Lanz
    Member

    Hi Dimitar

    Thank you. That was quick. And it works.

    Your code relies on a change of type of element e in tree.jqxTree(‘getItem’, e);
    First call: HTMLLIELement that represents a tree item => ajax()
    Second call: HTMLDivElement => no ajax()

    I rewrote the bind function as follows:

    tree.bind(‘expand’, function(event) {
    var parEl = event.args.element;
    var $parEl = $(parEl);

    var childEl = $parEl.find(‘ul:first’).children();
    var $childEl = $(childEl);

    // First call: HTMLLIELement that represents a tree item => ajax()
    // Second call: HTMLDivElement => return
    if (!tree.jqxTree(‘getItem’, $childEl[0])) {
    return;
    }

    var parItem = tree.jqxTree(‘getItem’, parEl)
    var parLabel = parItem.label;
    $.ajax({
    url: ‘edtree_expand’,
    data: {‘parent’: parLabel},
    success: function (data, status, xhr) {
    var items = jQuery.parseJSON(data);
    tree.jqxTree(‘addTo’, items, $parEl[0]);
    tree.jqxTree(‘removeItem’, $childEl[0]);
    }
    });

    return true;
    });

    However, the fact that I can rely on the fact the *all* labels in my tree are different allows the following:

    tree.bind(‘expand’, function(event) {
    var parEl = event.args.element;
    var $parEl = $(parEl);
    var childEl = $parEl.find(‘li’);
    var $childEl = $(childEl);

    var firstChildItem = tree.jqxTree(‘getItem’, $childEl[0]);
    if (firstChildItem.label != loadingLabel.label)
    return; // already loaded

    var parItem = tree.jqxTree(‘getItem’, parEl);

    $.ajax({
    url : ‘edtree_expand’,
    data: {‘parent’: parItem.label},
    success : function(jsonData, status, xhr) {
    tree.jqxTree(‘removeItem’, $childEl[0]);

    var childItems = jQuery.parseJSON(jsonData);

    // time to render in jqxTree addTo is a problem:
    tree.jqxTree(‘addTo’, childItems, parEl);
    }
    });
    return true;
    });

    Don’t know what I prefer. Anyway, my issue is solved. Thanks again!

    Best regards,
    René

Viewing 1 post (of 1 total)