1

我正在使用 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 继续。

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

4

1 回答 1

1

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

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

第一个ratings是部分的名称,第二个是你前面的列表。

试试看它是否有效。

于 2014-06-19T16:09:23.700 回答