通过数据组装部分循环

时间:2014-06-18 21:00:36

标签: handlebars.js assemble

我使用Assemble生成新网站,并希望尽可能模块化。其中一个组件将循环遍历数据列表并生成项目列表。

我的组件称为评级,如下所示:

---
ratings:
    - review: I would recommend this company.
      reviewRating: 10
      reviewLocation: Berkhamsted 
      reviewDate: 11/03/2014
    - review: Very pleasant, very prompt, fantastic, I would recommend them.
      reviewRating: 10
      reviewLocation: Cranbrook 
      reviewDate: 11/02/2014
    - review: Very reliable and very nice people to have around your property, great workmanship.
      reviewRating: 10
      reviewLocation: Chelmsford 
      reviewDate: 16/10/2013
    - review: Excellent service and I have recommended them to other people
      reviewRating: 10
      reviewLocation: Dartford 
      reviewDate: 14/06/2013
    - review: Very professional and great installation. I would have them back. Couldn't more pleased with them. Outstanding, top class.
      reviewRating: 10
      reviewLocation: Halstead
      reviewDate: 29/04/2013
---

{{#forEach ratings}}
    {{reviewRating}} - {{review}} -- {{reviewLocation}} --- {{reviewDate}}
{{/forEach}}

在我的页面中,我有以下内容:

{{> ratings }}

当我编译汇编文件时,我收到以下错误

警告:无法读取属性'长度'未定义使用--force继续。

但是当我在页面中包含数据和循环时,它工作正常,但不允许重复使用。

1 个答案:

答案 0 :(得分:1)

使用部分名称组装v0.4.x名称空间部分前端问题,因此您应该能够像...一样访问它...

{{#forEach ratings.ratings}}
    {{reviewRating}} - {{review}} -- {{reviewLocation}} --- {{reviewDate}}
{{/forEach}}

第一个ratings是部分名称,第二个“评级”是您前面的列表。

试一试,看看它是否有效。