精华内容
下载资源
问答
  • 获取子节点

    2019-09-23 23:37:11
    获取子节点的方法有: 方法 说明 children() 选取子节点,可以带过滤参数。但只能选择子节点,不能选择孙子节点。 find() 选取子节点,可以带过滤参数。可以选择子节点及孙子节点。 ...

    获取子节点的方法有:

     方法  说明
     children()  选取子节点,可以带过滤参数。但只能选择子节点,不能选择孙子节点。
     find()  选取子节点,可以带过滤参数。可以选择子节点及孙子节点。

    children()示例:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>子节点</title>
            <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"></script>
            <style>
                .box{
                    border: 1px solid blueviolet;
                    padding: 1px;
                    margin-bottom: 12px;
                }
            </style>
        </head>
        <body>
            <div>
                <ul id="ul">
                    <li id="a">鼠标</li>
                    <li id="b">键盘</li>
                    <li id="c">屏幕</li>
                    <li id="d"><a>电源</a></li>
                </ul>
            </div>
            <script>
                $('div').children("*").attr("class", "box");
            </script>
        </body>
    </html>

    find()示例:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>子节点</title>
            <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.3.1.min.js"></script>
            <style>
                .box{
                    border: 1px solid blueviolet;
                    padding: 1px;
                    margin-bottom: 12px;
                }
            </style>
        </head>
        <body>
            <div>
                <ul id="ul">
                    <li id="a">鼠标</li>
                    <li id="b">键盘</li>
                    <li id="c">屏幕</li>
                    <li id="d"><a>电源</a></li>
                </ul>
            </div>
            <script>
                $('div').find("ul").attr("class", "box");
            </script>
        </body>
    </html>

     

    转载于:https://www.cnblogs.com/max-hou/p/9132044.html

    展开全文
  • 工作中因业务需求,将数据库中的树状结构的数据根据父节点...分组后递归获取子节点,有子节点的添加,没有的设置子节点并删除分组的数据,知道分组数据删完Tree.java@Datapublic class Tree {private Integer id;pri...

    工作中因业务需求,将数据库中的树状结构的数据根据父节点获取所有的子节点

    实现思路

    1.获取整个数据的list集合数据

    2.将数据分组,java8 list有groupby分组,java8之前的自己遍历整理

    3.分组后递归获取子节点,有子节点的添加,没有的设置子节点并删除分组的数据,知道分组数据删完

    Tree.java

    @Data

    public class Tree {

    private Integer id;

    private Integer pId;

    private String key;

    private String value;

    private List childList;

    }

    TreeUtils.java

    public class TreeUtils {

    static List trees ;

    static {

    String jsonStr = "[" +

    "{\"id\":100,\"pId\":1,\"key\":\"root\", \"value\": \"root\"}," +

    "{\"id\":1000,\"pId\":100,\"key\":\"node1\", \"value\": \"node1\"}," +

    "{\"id\":2000,\"pId\":100,\"key\":\"node2\",\"value\": \"node2\"}," +

    "{\"id\":3000,\"pId\":100,\"key\":\"node3\",\"value\": \"node3\"}," +

    "{\"id\":1100,\"pId\":1000,\"key\":\"node11\",\"value\": \"node11\"}," +

    "{\"id\":1200,\"pId\":1000,\"key\":\"node12\",\"value\": \"node12\"}," +

    "{\"id\":1110,\"pId\":1100,\"key\":\"node111\",\"value\": \"node111\"}," +

    "{\"id\":1120,\"pId\":1100,\"key\":\"node112\",\"value\": \"node112\"}," +

    "{\"id\":2100,\"pId\":2000,\"key\":\"node21\",\"value\": \"node21\"}," +

    "{\"id\":2200,\"pId\":2000,\"key\":\"node22\",\"value\": \"node22\"}," +

    "{\"id\":2110,\"pId\":2100,\"key\":\"node211\",\"value\": \"node21\"}" +

    "]";

    trees = JSONObject.parseArray(jsonStr, Tree.class);

    }

    public static void main(String[] args) {

    Tree tree = metaTree(trees, 100);

    /**

    * Tree@6073f712[id=100,pId=1,key=root,value=root,childList=[

    * Tree(id=1000, pId=100, key=node1, value=node1, childList=[

    * Tree(id=1100, pId=1000, key=node11, value=node11, childList=[

    * Tree(id=1110, pId=1100, key=node111, value=node111, childList=null),

    * Tree(id=1120, pId=1100, key=node112, value=node112, childList=null)]),

    * Tree(id=1200, pId=1000, key=node12, value=node12, childList=null)]),

    * Tree(id=2000, pId=100, key=node2, value=node2, childList=[

    * Tree(id=2100, pId=2000, key=node21, value=node21, childList=[

    * Tree(id=2110, pId=2100, key=node211, value=node21, childList=null)]),

    * Tree(id=2200, pId=2000, key=node22, value=node22, childList=null)]),

    * Tree(id=3000, pId=100, key=node3, value=node3, childList=null)]]

    */

    System.out.println("tree:" + ToStringBuilder.reflectionToString(tree));

    }

    private static Tree metaTree(List treeList, Integer id) {

    //此处getId getPId根据自己实际情况更改

    Tree treeConfig = treeList.stream().filter(tree -> tree.getId().equals(id)).collect(Collectors.toList()).get(0);

    Map> collect = treeList.stream().filter(type -> type.getPId() != null).collect(Collectors.groupingBy(Tree::getPId));

    if (collect != null && collect.size() > 0) {

    recursion(collect, treeConfig);

    }

    return treeConfig;

    }

    private static Tree recursion(Map> maps, Tree tree) {

    if (tree.getChildList() == null) {

    if (maps.get(tree.getId()) != null) {

    tree.setChildList(maps.get(tree.getId()));

    maps.remove(tree.getId());

    if (maps.size() > 0) {

    recursion(maps, tree);

    }

    }

    } else {

    List metaTypeList = tree.getChildList();

    if (metaTypeList != null && metaTypeList.size() > 0) {

    for (Tree meta : metaTypeList) {

    recursion(maps, meta);

    }

    }

    }

    return tree;

    }

    }

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    展开全文
  • 本篇文章小编给大家分享一下Java list根据id获取子节点代码,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。实现思路1.获取整个数据的list集合数据2.将数据分组,java8 list有groupby...

    本篇文章小编给大家分享一下Java list根据id获取子节点代码,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

    实现思路

    1.获取整个数据的list集合数据

    2.将数据分组,java8 list有groupby分组,java8之前的自己遍历整理

    3.分组后递归获取子节点,有子节点的添加,没有的设置子节点并删除分组的数据,知道分组数据删完

    Tree.java

    @Data

    public class Tree {

    private Integer id;

    private Integer pId;

    private String key;

    private String value;

    private ListchildList;

    }

    TreeUtils.java

    public class TreeUtils {

    static Listtrees ;

    static {

    String jsonStr = "[" +

    "{\"id\":100,\"pId\":1,\"key\":\"root\", \"value\": \"root\"}," +

    "{\"id\":1000,\"pId\":100,\"key\":\"node1\", \"value\": \"node1\"}," +

    "{\"id\":2000,\"pId\":100,\"key\":\"node2\",\"value\": \"node2\"}," +

    "{\"id\":3000,\"pId\":100,\"key\":\"node3\",\"value\": \"node3\"}," +

    "{\"id\":1100,\"pId\":1000,\"key\":\"node11\",\"value\": \"node11\"}," +

    "{\"id\":1200,\"pId\":1000,\"key\":\"node12\",\"value\": \"node12\"}," +

    "{\"id\":1110,\"pId\":1100,\"key\":\"node111\",\"value\": \"node111\"}," +

    "{\"id\":1120,\"pId\":1100,\"key\":\"node112\",\"value\": \"node112\"}," +

    "{\"id\":2100,\"pId\":2000,\"key\":\"node21\",\"value\": \"node21\"}," +

    "{\"id\":2200,\"pId\":2000,\"key\":\"node22\",\"value\": \"node22\"}," +

    "{\"id\":2110,\"pId\":2100,\"key\":\"node211\",\"value\": \"node21\"}" +

    "]";

    trees = JSONObject.parseArray(jsonStr, Tree.class);

    }

    public static void main(String[] args) {

    Tree tree = metaTree(trees, 100);

    /**

    * Tree@6073f712[id=100,pId=1,key=root,value=root,childList=[

    * Tree(id=1000, pId=100, key=node1, value=node1, childList=[

    * Tree(id=1100, pId=1000, key=node11, value=node11, childList=[

    * Tree(id=1110, pId=1100, key=node111, value=node111, childList=null),

    * Tree(id=1120, pId=1100, key=node112, value=node112, childList=null)]),

    * Tree(id=1200, pId=1000, key=node12, value=node12, childList=null)]),

    * Tree(id=2000, pId=100, key=node2, value=node2, childList=[

    * Tree(id=2100, pId=2000, key=node21, value=node21, childList=[

    * Tree(id=2110, pId=2100, key=node211, value=node21, childList=null)]),

    * Tree(id=2200, pId=2000, key=node22, value=node22, childList=null)]),

    * Tree(id=3000, pId=100, key=node3, value=node3, childList=null)]]

    */

    System.out.println("tree:" + ToStringBuilder.reflectionToString(tree));

    }

    private static Tree metaTree(ListtreeList, Integer id) {

    //此处getId getPId根据自己实际情况更改

    Tree treeConfig = treeList.stream().filter(tree -> tree.getId().equals(id)).collect(Collectors.toList()).get(0);

    Map> collect = treeList.stream().filter(type -> type.getPId() != null).collect(Collectors.groupingBy(Tree::getPId));

    if (collect != null && collect.size() > 0) {

    recursion(collect, treeConfig);

    }

    return treeConfig;

    }

    private static Tree recursion(Map> maps, Tree tree) {

    if (tree.getChildList() == null) {

    if (maps.get(tree.getId()) != null) {

    tree.setChildList(maps.get(tree.getId()));

    maps.remove(tree.getId());

    if (maps.size() > 0) {

    recursion(maps, tree);

    }

    }

    } else {

    ListmetaTypeList = tree.getChildList();

    if (metaTypeList != null && metaTypeList.size() > 0) {

    for (Tree meta : metaTypeList) {

    recursion(maps, meta);

    }

    }

    }

    return tree;

    }

    }

    展开全文
  • 工作中因业务需求,将数据库中的树状结构的数据根据父节点...分组后递归获取子节点,有子节点的添加,没有的设置子节点并删除分组的数据,知道分组数据删完Tree.java@Datapublic class Tree {private Integer id;pri...

    工作中因业务需求,将数据库中的树状结构的数据根据父节点获取所有的子节点

    实现思路

    1.获取整个数据的list集合数据

    2.将数据分组,java8 list有groupby分组,java8之前的自己遍历整理

    3.分组后递归获取子节点,有子节点的添加,没有的设置子节点并删除分组的数据,知道分组数据删完

    Tree.java

    @Data

    public class Tree {

    private Integer id;

    private Integer pId;

    private String key;

    private String value;

    private List childList;

    }

    TreeUtils.java

    public class TreeUtils {

    static List trees ;

    static {

    String jsonStr = "[" +

    "{"id":100,"pId":1,"key":"root", "value": "root"}," +

    "{"id":1000,"pId":100,"key":"node1", "value": "node1"}," +

    "{"id":2000,"pId":100,"key":"node2","value": "node2"}," +

    "{"id":3000,"pId":100,"key":"node3","value": "node3"}," +

    "{"id":1100,"pId":1000,"key":"node11","value": "node11"}," +

    "{"id":1200,"pId":1000,"key":"node12","value": "node12"}," +

    "{"id":1110,"pId":1100,"key":"node111","value": "node111"}," +

    "{"id":1120,"pId":1100,"key":"node112","value": "node112"}," +

    "{"id":2100,"pId":2000,"key":"node21","value": "node21"}," +

    "{"id":2200,"pId":2000,"key":"node22","value": "node22"}," +

    "{"id":2110,"pId":2100,"key":"node211","value": "node21"}" +

    "]";

    trees = JSONObject.parseArray(jsonStr, Tree.class);

    }

    public static void main(String[] args) {

    Tree tree = metaTree(trees, 100);

    /**

    * Tree@6073f712[id=100,pId=1,key=root,value=root,childList=[

    * Tree(id=1000, pId=100, key=node1, value=node1, childList=[

    * Tree(id=1100, pId=1000, key=node11, value=node11, childList=[

    * Tree(id=1110, pId=1100, key=node111, value=node111, childList=null),

    * Tree(id=1120, pId=1100, key=node112, value=node112, childList=null)]),

    * Tree(id=1200, pId=1000, key=node12, value=node12, childList=null)]),

    * Tree(id=2000, pId=100, key=node2, value=node2, childList=[

    * Tree(id=2100, pId=2000, key=node21, value=node21, childList=[

    * Tree(id=2110, pId=2100, key=node211, value=node21, childList=null)]),

    * Tree(id=2200, pId=2000, key=node22, value=node22, childList=null)]),

    * Tree(id=3000, pId=100, key=node3, value=node3, childList=null)]]

    */

    System.out.println("tree:" + ToStringBuilder.reflectionToString(tree));

    }

    private static Tree metaTree(List treeList, Integer id) {

    //此处getId getPId根据自己实际情况更改

    Tree treeConfig = treeList.stream().filter(tree -> tree.getId().equals(id)).collect(Collectors.toList()).get(0);

    Map> collect = treeList.stream().filter(type -> type.getPId() != null).collect(Collectors.groupingBy(Tree::getPId));

    if (collect != null && collect.size() > 0) {

    recursion(collect, treeConfig);

    }

    return treeConfig;

    }

    private static Tree recursion(Map> maps, Tree tree) {

    if (tree.getChildList() == null) {

    if (maps.get(tree.getId()) != null) {

    tree.setChildList(maps.get(tree.getId()));

    maps.remove(tree.getId());

    if (maps.size() > 0) {

    recursion(maps, tree);

    }

    }

    } else {

    List metaTypeList = tree.getChildList();

    if (metaTypeList != null && metaTypeList.size() > 0) {

    for (Tree meta : metaTypeList) {

    recursion(maps, meta);

    }

    }

    }

    return tree;

    }

    }

    展开全文
  • 本文实例讲述了JS获取子节点、父节点和兄弟节点的方法。分享给大家供大家参考,具体如下: 一、js获取子节点的方式 1. 通过获取dom方式直接获取子节点 其中test的父标签id的值,div为标签的名字。...
  • JS获取子节点、父节点和兄弟节点的若干种方式

    万次阅读 多人点赞 2017-07-22 16:50:49
    一、js获取子节点的方式1.通过获取dom方式直接获取子节点其中test的父标签id的值,div为标签的名字。getElementsByTagName是一个方法。返回的是一个数组。在访问的时候要按数组的形式访问。var a = document....
  • JS获取子节点、父节点和兄弟节点 1. JS获取子节点、父节点和兄弟节点 【一】获取子节点 通过获取dom方式直接获取子节点 通过childNodes集合,获取子节点 使用childNodes获取子节点的时候,childNodes返回的是子...
  • <script type="text/javascript" src="jquery-1.7.1.min.js"></script> <Script type="text/javascript">...//获取子节点 , 子节点数量 for (i=0;i<Snum;i++) { $('#bg').children()..
  • 主要介绍了父节点获取子节点的字符串的方法,需要的朋友可以参考下
  • 获取子节点和父节点的方法有很多,在本文为大家详细介绍下jquery中时如何实现的,感兴趣的朋友可以参考下
  • 0x02 DOM获取子节点 1.childNodes: 2.children 0x03 获取父节点 0x04判断节点类型 0x05 获取子节点和兄弟节点 1.获取第一个子节点 2.获取最后一个子节点 3.获取兄弟节点 1.获取上一个兄弟节点 2.获取下一...
  • 本文实例讲述了JS获取子节点、父节点和兄弟节点的方法。分享给大家供大家参考,具体如下: 一、js获取子节点的方式 1. 通过获取dom方式直接获取子节点 其中test的父标签id的值,div为标签的名字。...
  • 本文实例讲述了JS获取子节点、父节点和兄弟节点的方法。分享给大家供大家参考,具体如下:一、js获取子节点的方式1. 通过获取dom方式直接获取子节点其中test的父标签id的值,div为标签的名字。getElementsByTagName...
  • 主要介绍了Java list如何根据id获取子节点,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
  • childNodes 访问当前节点下所有的子节点 firstChild 访问子节点中的首位 lastChild 访问子节点中的最后一位 <!DOCTYPE html> <html lang="en"> <head>...获取子节点</t...
  • Java中list根据id获取子节点的示例发布时间:2021-02-01 10:43:18来源:亿速云阅读:70作者:小新这篇文章主要介绍了Java中list根据id获取子节点的示例,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完...
  • jQuery.获取子节点

    2018-07-23 15:53:00
    获取子节点 方法 说明 children() 选取子节点,可以带过滤参数。但只能选择子节点,不能选择孙子节点。 find() 选取子节点,可以带过滤参数。可以选择子节点及孙子节点。 <!...
  • 071|获取子节点

    2020-08-05 16:29:05
    071获取子节点</title> <script> /* 以下5个属性都包含文本节点 childNodes 访问当前节点下所有的节点 firstChild 访问子节点中的首位 lastChild 访问字节点的最后一位 n...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,182
精华内容 2,072
关键字:

获取子节点