1. #1
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,814
    Vote Rating
    607
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default HOW-TO: Get rid of the expand for a tree node you know is empty

    HOW-TO: Get rid of the expand for a tree node you know is empty


    An issue I've had with an Ext app is that when loading a tree asynchronously, on the server side I already know that the node has no children, however as far as I can tell there is no easy way to communicate this back to Ext (please correct me if there is an easier way).

    So, if you know beforehand that your node is empty, when sending the JSON back to the client, include:
    Code:
    {isLoaded: true}
    for the appropriate nodes.

    Then in your tree code, use:
    Code:
    tree.on('beforeload', function(node)
    {
       if (node.attributes['isLoaded'])
          return false; //we know the node is empty, don't querying the server
    }, this);
    
    tree.on('load', function(node)
    {
       var children = node.childNodes;
       for (var i = 0; i < children.length; i++)
       {
          var n = children[i];
          if (n.attributes['isLoaded'])
             n.expand(); //force the node to expand
       }
    }, this);
    This technique is useful when there is not necessarily always a leaf node (a folder structure would be a good example of this).

  2. #2
    Ext User GalaxySong's Avatar
    Join Date
    May 2007
    Posts
    51
    Vote Rating
    0
    GalaxySong is on a distinguished road

      0  

    Default


    Why not just use "leaf = true" instead of "isLoaded = true"?

  3. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,814
    Vote Rating
    607
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Because the node might not always be a leaf (for example if you're creating a folder structure, it might be a leaf for the time being, however when you add a child folder it is no longer a leaf).

  4. #4
    Sencha Premium Member
    Join Date
    Mar 2007
    Location
    Iloilo, Philippines
    Posts
    149
    Vote Rating
    1
    willydee is on a distinguished road

      0  

    Thumbs up


    evant,
    this was very helpful, thanks for pointing out!
    Kind regards,
    WillyDee

    Problems worthy of attack, prove their worth by hitting back.

  5. #5
    Sencha User jack.slocum's Avatar
    Join Date
    Mar 2007
    Location
    Tampa, FL
    Posts
    6,955
    Vote Rating
    17
    jack.slocum will become famous soon enough jack.slocum will become famous soon enough

      0  

    Default


    Actually, you can tell it it has no children when loading by returning an empty children array attribute:

    children: []

    Then, you can make it immediately "discover" that it has no children and remove the expand icon with:

    expanded: true

    A complete example:

    Code:
    {
        id: 'my-id',
        text: 'I have no children right now',
        iconCls: 'foo-icon',
        children: [],
        expanded: true
    }
    Jack Slocum
    Ext JS Founder
    Original author of Ext JS 1, 2 & 3.
    Twitter: @jackslocum
    jack@extjs.com

  6. #6
    Sencha Premium Member
    Join Date
    Mar 2007
    Location
    Iloilo, Philippines
    Posts
    149
    Vote Rating
    1
    willydee is on a distinguished road

      0  

    Arrow


    Perhaps the shortest way (assumed a numeric 'Children' property is supplied with the JSON data), otherwise almost the same as evant's solution:

    PHP Code:
    loader.on('beforeload', function(loadernode) {
        if (
    node.attributes.Children == 0) return false;
    });
    loader.on('load', function(loadernode) {
        
    node.eachChild(function(child) {
            if (
    child.attributes.Children == 0child.expand();
        });
    }); 
    Kind regards,
    WillyDee

    Problems worthy of attack, prove their worth by hitting back.

  7. #7
    Ext User GalaxySong's Avatar
    Join Date
    May 2007
    Posts
    51
    Vote Rating
    0
    GalaxySong is on a distinguished road

      0  

    Default


    I think Jack's way is convenient enough.

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi