胡须迭代数组的对象

我正在寻找迭代数组对象的列表

这是我的示例对象

var Categories = { "communication": [ { "id": "communication_001", "category": "communication", "lastModified": "4 Day ago" }, { "id": "communication_002", "category": "communication", "lastModified": "1 Day ago" } ], "social": [ { "id": "social_001", "category": "social", "lastModified": "2 Day ago" } ], "storage": [ { "id": "storage_001", "category": "storage", "lastModified": "3 Day ago" } ] } 

在这里,我正在胡须

 var htmlTemplate= Mustache.render(template, { connectors: Categories }); 

那么我的编译模板是什么?

build议我胡子模板。

一个可能的模板:

 {{#connectors}} Communication<br> {{#communication}} {{id}} - {{category}} - {{lastModified}}<br> {{/communication}} <br><br>Social<br> {{#social}} {{id}} - {{category}} - {{lastModified}}<br> {{/social}} <br><br>Storage<br> {{#storage}} {{id}} - {{category}} - {{lastModified}}<br> {{/storage}} {{/connectors}} 

这产生这个:

 Communication communication_001 - communication - 4 Day ago communication_002 - communication - 1 Day ago Social social_001 - social - 2 Day ago Storage storage_001 - storage - 3 Day ago 

要在列表中进行迭代,我将使用这些部分,根据列表是否为空,其行为将有所不同:

  • 空列表:这些部分不会被渲染
  • 非空列表:对列表中的每一个元素,这些部分将被渲染一次,该部分的上下文被设置为当前的项目,允许你调用它的属性并循环访问列表。

但是你可以在模板中做更多的事情,所以你应该检查文档 。