Jade get object children with loop in loop

Jade get object children with loop in loop

我想循环 object 通过路由器传递的数据。我可以很好地循环 object 的第一级,但是当我添加尝试循环 children 时,jade 提示我`无法读取未定义的 属性 'length'。代码:

这部分工作得很好:

- each item in index
    - var module = item
    h3= item.name
    p Included: #{item.path}
    p= item.children

我什至将 children 视为 [object Object],[object Object],但是当我添加另一个循环时:

- each item in index
    - var module = item
    h3= item.name
    p Included: #{item.path}
    p= item.children

    - var children = item.children
    - each child in children
        +module(child)

它不再起作用了。这可能是什么原因?

发现我的错误:元素不能为空,因此最好在循环之前检查变量。有些 children 是空的,因此提示 Cannot read property 'length' of undefined.

- each item in index
    - var module = item
    h3= item.name
    p Included: #{item.path}

    if item.children
        - var children = item.children
        - each child in children
            +module(child)
    hr

这有效。