Recursive iteration over an object in Jade template?

前端 未结 3 1571
一个人的身影
一个人的身影 2021-02-05 14:32

I have an object of mixed type properties - some strings, some arrays of strings, some objects containing arrays of strings - that can potentially go many levels deep.

I

3条回答
  •  执笔经年
    2021-02-05 14:50

    It's been a while since you asked, but mixin is your friend, I think. I haven't tried it out, but if mixins support recursion, this should work:

    mixin parseObject(obj)
      div
        - each val, key in obj
          - if (typeof val === 'string')
            span #{val}
          - else if (typeof val === 'object')
            mixin parseObject(val)
    

    Then in the body of your .jade file, call mixin parseObject(rootObject).

提交回复
热议问题