Recursive iteration over an object in Jade template?

前端 未结 3 1572
一个人的身影
一个人的身影 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 15:04

    Recursion seems to be suppported now. I have successfully used the function with a minor tweak; you need to use the mixin keyword when calling the function.

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

提交回复
热议问题