1

我定义了一个 Ember 对象,它从 .json 文件中获取数据。

我正在使用 ember 和 x-handlebars 从已使用 Ember 数组控制器定义为 Ember 对象的一部分的数组输出图像。

数组定义如下:

{
     "gallery_small": ["data/images/gallery_01_small.jpg", "data/images/gallery_02_small.jpg"]  
}

我当前的 html 是:

{{#each content.gallery_small}}
     {{#collection contentBinding="Application.projectdetailController"}}
          {{content.gallery_small}}
     {{/collection}}
{{/each}}

当前输出的是

data/images/gallery_01_small.jpg,data/images/gallery_02_small.jpg
data/images/gallery_01_small.jpg,data/images/gallery_02_small.jpg

我想要的是

data/images/gallery_01_small.jpg
data/images/gallery_02_small.jpg

我怎样才能得到这个?

非常感谢!

4

1 回答 1

2

通过这样做{{#collection contentBinding="Application.projectdetailController"}},您正在定义一个新的上下文。所以在 {{content.gallery_small}} 中,内容是 Application.projectdetailController 的一个对象,它似乎是数组。

我会试试这个:

{{#each image in Application.projectdetailController.content}}
    {{image}}
{{/each}}

如果它不起作用,请使用您的完整代码更新您的问题,或创建一个 jsfiddle,以便我更好地理解问题所在。

于 2012-07-30T19:51:31.637 回答