how to use for each with mustache javascript?

对着背影说爱祢 提交于 2019-12-04 03:56:39

data needs to be an array (see the enclosing [])

var data = [{
  "msg_id": "134",
  "message": "Nick",
  "comment": [{
    "com_id": "9",
    "comment": "test",
  }, {
    "com_id": "10",
    "comment": "testtt",
  }, {
    "com_id": "11",
    "comment": "testtttt",
  }]
}, {
  "msg_id": "134",
  "message": "Nick",
}, {
  "msg_id": "134",
  "message": "Nick",
}]

is just this in mustache templates:

{{#data}}         //loop through all data
  {{message}}     //pick out the "message" per iteration
  {{#comment}}    //loop through all comments in an iterated item
    {{comment}}   //pick out the comment
  {{/comment}}
{{/data}}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!