Can mustache iterate a top-level array?

前端 未结 5 863
刺人心
刺人心 2020-12-04 08:21

My object looks like this:

[\'foo\',\'bar\',\'baz\']

And I want to use a mustache template to produce from it something like this:

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 08:57

    I don't think mustache can do this! (surprisingly) You can iterate over a list of objects, and then access the attributes of each object, but you can't seem to iterate over a simple list of values!

    So, you have to transform your list into:

    [ {"value":"foo"},{"value":"bar"},{"value":"baz"} ] 
    

    and then your template would be:

      {{#the_list}}
    • {{value}}
    • {{/the_list}}

    To me, this seems like a severe problem with Mustache -- any template system should be able to loop over a list of simple values!

提交回复
热议问题