我想遍历这样的数据,得到qx为1的节点,和这个节点的直接子节点,数据格式为这样
[
  {
    "thisNode": "10000480",
    "prientNode": "",
    "qx": "0",
    "children": [
      {
        "prientNode": "10000480",
        "thisNode": "10000470",
        "qx": "0",
        "children": []
      },
      {
        "prientNode": "10000480",
        "thisNode": "10000420",
        "children": [
          {
            "prientNode": "10000420",
            "thisNode": "10000551",
            "qx": "1",
            "children": [
              {
                "prientNode": "10000420",
                "thisNode": "10000551",
                "qx": "1",
                "children": []
              }
            ]
          }
        ]
      }
    ]
  }
]

解决方案 »

  1.   


        d = [{
            "thisNode": "10000480",
            "prientNode": "",
            "qx": "0",
            "children": [
              {
                  "prientNode": "10000480",
                  "thisNode": "10000470",
                  "qx": "0",
                  "children": []
              },
              {
                  "prientNode": "10000480",
                  "thisNode": "10000420",
                  "children": [
                    {
                        "prientNode": "10000420",
                        "thisNode": "10000551",
                        "qx": "1",
                        "children": [
                          {
                              "prientNode": "10000420",
                              "thisNode": "10000551",
                              "qx": "1",
                              "children": []
                          }
                        ]
                    }
                  ]
              }
            ]
        }
        ];
        function findChildren(arr, key, value,callback) {
            for (var i = 0; i < arr.length; i++) {
                if (arr[i][key] == value) callback(arr[i].children)
                findChildren(arr[i].children, key, value, callback);
            }
        }
        findChildren(d, 'qx', '1', function (children) {
            console.log(children)
        });Web开发学习资料推荐
    jqGrid colModel配置参数
    Web前端开发教程