Can mustache iterate a top-level array?

前端 未结 5 865
刺人心
刺人心 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 09:04

    You can do it like this...

    Mustache.render('
      {{#.}}
    • {{.}}
    • {{/.}}
    ', ['foo','bar','baz']);

    It also works for things like this...

    var obj = [{name: 'foo'}, {name: 'bar'}];
    var tmp = '
      {{#.}}
    • {{name}}
    • {{/.}}
    '; Mustache.render(tmp, obj);

提交回复
热议问题