求助,递归 如果满足条件把json对象赋值成该对象的children[0] 代码执行后 实际结果没有改变

YunY_1986 2022-07-05 15:58:13

let jsonStr = {"filterType":"or","children":[{"filterType":"and","children":[{"eidter":false,"tablea":"","fielda":"","symbol":"=","conditionFrom":0,"tableb":"","fieldb":"","context":""}]},{"eidter":false,"tablea":"","fielda":"","symbol":"=","conditionFrom":0,"tableb":"","fieldb":"","context":""}]}
function clearFilters (wconfig, level = 0) {
      if (wconfig.children) {
        wconfig.children.forEach(c => {
          if (c.children) {
            c = this.clearFilters(c, level + 1)
          }
        });
        wconfig.children = wconfig.children.filter(wc => (wc.eidter === undefined && wc.children.length > 0) || wc.eidter === false)
        if (wconfig.children.length === 1) {
          wconfig = wconfig.children[0];
        }
      }
      return wconfig;
    }

clearFilters(jsonStr)

 

------------------------------

if (wconfig.children.length === 1) {
          wconfig = wconfig.children[0];
        }

这段代码实际是有执行,但是 没有效果 求大神解释一下原因呢?

 

...全文
71 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复
相关推荐
发帖
JavaScript

8.6w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2022-07-05 15:58
社区公告
暂无公告