简体   繁体   English

Handlebars.js:分配给模板时为空道具

[英]Handlebars.js: empty propetry when assigning to template

When I log, it shows: 当我登录时,它显示:

"names": {
    "en": "X"
},
"images": [
    "https://x.com/1.jpg"
]

and the Template is: 模板是:

<div>{{images.[1]}}</div>                       
<div>{{names.en}}</div>

But images' div is empty. 但是图像的div为空。

How to fix this? 如何解决这个问题?

Try: 尝试:

<div>{{images.[0]}}</div>   

Handlebars syntax is weird, if you are accessing an element in an array, do this: 句柄语法很奇怪,如果要访问数组中的元素,请执行以下操作:

{{images.[0]}}

This doesn't work: 这不起作用:

{{images[0]}}
{{images.0}}

But, if the element has a nested property you can do this: 但是,如果元素具有嵌套属性,则可以执行以下操作:

{{images.0.otherProp}}
<div>{{images[0]}}</div>                       
<div>{{names.en}}</div>

images is an array and array index starts from 0. images是一个数组,数组索引从0开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM