ExtJS equivalent of jQuery kids?

I tried to implement the children function in ExtJS using select ("~ *"), it just didn't work.

I just want ExtJS to return me the set of the immediate child node and ignore all the nodes under the child nodes.

<div>
    <span>
        <img/>
        <img/>
    </span>
    <span>
        <img/>
        <img/>
    </span>
    <span>
        <img/>
        <img/>
    </span>
</div>

In fact, I just need the number of immediate children. If I get the right choice, I can do getCount () in CompositeElement.

Any help would be greatly appreciated.

Cheers, Mickey

+3
source share
4 answers

If you can specify a parent, then you can do something like this to get children:

<div id='mydiv'>
    <span>
        <img/>
        <img/>
    </span>
    <span>
        <img/>
        <img/>
    </span>
    <span>
        <img/>
        <img/>
    </span>
</div>  

Define a function like this:

    function getChildren(parentId) {
      var kids = Ext.get(parentId).select('*');
      kids = kids.filter(function(el) {
            return el.parent().id == parentId
      });
      return kids;
    }      

In your example, getChildren('mydiv').getCount()will return 3.

+6
source

children ExtJS, select ( "~ *" ), .

, " > *". ExtJs :

var children = Ext.get("myDiv").query("> *");

<div id='mydiv'>
    <span>
        <img/>
        <img/>
    </span>
    <span>
        <img/>
        <img/>
    </span>
    <span>
        <img/>
        <img/>
    </span>
</div>  

HTML- ( 3 ).

+1

, DOM, , , , , Ext.Element.

Ext.CompositeElement Ext.Element. Ext.Element.select, Ext.Element.parent, Ext.Element.query, Ext.Element.next .., , .

: http://www.extjs.com/deploy/dev/docs/source/Element.fx.html#cls-Ext.Element

,

-bn

0

,

Ext.select('div span').getCount();

3 .

0

Source: https://habr.com/ru/post/1730071/


All Articles