Recursive iteration over an object in Jade template?

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

    In the modern version of Jade it's look like

    mixin parseObject( obj )
      div
        each val in obj
          if typeof val === 'string'
            span= val
          else if typeof val === 'object'
            +parseObject( val )
    

    Then in the body of your .jade file, call

    +parseObject( rootObject )

提交回复
热议问题