角翻译:JSON对象重复 [英] Angular translate : repeat on json object
问题描述
我有这样一个JSON文件:
I have a json file like this :
{
"pages": {
"page1": {
"field1": "....",
"field2": "....",
"field3": "....",
"thumbnails": [
{
"illustration": "images/img.png",
"content": "...."
},
{
"illustration": "images/img.png",
"content": "...."
},
{
"illustration": "images/img.png",
"content": "...."
}
]
},
......
当我想在我的HTML中使用它,我只是做:结果 {{'pages.page1.field1|翻译}}
例如:
When i want to use it in my html, i just do :
{{ 'pages.page1.field1' | translate }}
for example
但
如果我需要重复?对于缩略图。
What if i need to repeat ? For thumbnails.
<div ng-repeat="thumbnail in pages.page1.thumbnails">
{{ thumbnail.content }}
</div>
但显然它不工作。我不知道如何访问缩略图。
But obviously it's not working. I don't know how to access thumbnails.
的编辑1:的
我使用useStaticFilesLoader像这样在我的配置:
I'm using "useStaticFilesLoader" like this in my config :
$translateProvider.useStaticFilesLoader({
prefix: 'assets/app_components/app/languages/emag_',
suffix: '.json'
});
所以,我没有一个JSON定义为我的控制器。
So i don't have a json defined into my controller.
的编辑2 的:
为了更precise,这里是什么我究竟想做一个plunkr:为了帮助您了解什么是我的问题,我在这里做了一个小plunkr:的 http://plnkr.co/edit/mocztnQYvmmuc3Nslmnb?p=$p$pview
推荐答案
您有坏的JSON file.You有对象的对象。你需要阵列。
You have bad json file.You have objects in object. You need array.
试试这个。
{
"thumbnails": [
{
"illustration": "images/img.png",
"content": "...."
},
{
"illustration": "images/img.png",
"content": "...."
},
{
"illustration": "images/img.png",
"content": "...."
}
]
}
我认为,NG-重复使用阵列只能是因为NG-重复需要知道lenght。
I think that ng-repeat works only with array because ng-repeat need know lenght.
Sry基因的英文不好:)
Sry for bad english :)
页面相同的问题。
{
"pages": [
{
"fields": [
"...",
"...",
"...."
],
"thumbnails": [
{
"illustration": "image/img_01.png",
"content": "...."
},
{
"illustration": "image/img_01.png",
"content": "...."
},
{
"illustration": "image/img_01.png",
"content": "...."
}
]
}
]
}
这篇关于角翻译:JSON对象重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!