assemble: eachIndex or each get no index
assemble: eachIndex or each get no index
我循环遍历一个数组,我需要索引...它循环,但我没有得到索引...{{this.title}} 和 {{this.content 的输出}} 作品
{{> accordion data=home.services}}
我的手风琴
{{#each data}}
<div class="c_accordion__item c_accordion__item--active">
<header class="c_accordion__header">
<a href="js_item-{{@index}}" class="link js_accordion_toggle">
<svg class="c_accordion__toggle-icon icon-arrow">
<use xlink:href="#arrow"></use>
<svg>
<h1 class="largest c_accordion__title">
{{this.title}}
</h1>
</a>
</header>
<div id="js_item-{{@index}}" class="c_accordion__content">
<p>{{this.content}}</p>
<a href="#" class="link c_accordion__more">mehr lesen</a>
</div>
</div>
{{/each}}
我的json
{
...
"services":[
{
"title": "headline1",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
},
{
"title": "headline2",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
},
{
"title": "headline3",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
},
....
]
}
我还用 http://assemble.io/helpers/helpers-collections.html
中的 eachIndex 尝试了这个助手
是的,我先安装了它 ;) (npm i handlebars-helpers --save-dev)
它只循环,但我没有得到索引的值,也没有得到 data.title 或 data.content
的值
格雷戈尔
我发现了,它与 eachindex 一起使用,以获取您必须使用的索引 "this" 并获取 obj 的属性。 "item"
{{#eachIndex data}}
<div class="c_accordion__item c_accordion__item--active">
<header class="c_accordion__header">
<a href="js_item-{{this.index}}" class="link js_accordion_toggle">
<svg class="c_accordion__toggle-icon icon-arrow">
<use xlink:href="#arrow"></use>
<svg>
<h1 class="largest c_accordion__title">
{{item.title}}
</h1>
</a>
</header>
<div id="js_item-{{this.index}}" class="c_accordion__content">
<p>{{item.content}}</p>
<a href="#" class="link c_accordion__more">mehr lesen</a>
</div>
</div>
{{/eachIndex}}
我循环遍历一个数组,我需要索引...它循环,但我没有得到索引...{{this.title}} 和 {{this.content 的输出}} 作品
{{> accordion data=home.services}}
我的手风琴
{{#each data}}
<div class="c_accordion__item c_accordion__item--active">
<header class="c_accordion__header">
<a href="js_item-{{@index}}" class="link js_accordion_toggle">
<svg class="c_accordion__toggle-icon icon-arrow">
<use xlink:href="#arrow"></use>
<svg>
<h1 class="largest c_accordion__title">
{{this.title}}
</h1>
</a>
</header>
<div id="js_item-{{@index}}" class="c_accordion__content">
<p>{{this.content}}</p>
<a href="#" class="link c_accordion__more">mehr lesen</a>
</div>
</div>
{{/each}}
我的json
{
...
"services":[
{
"title": "headline1",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
},
{
"title": "headline2",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
},
{
"title": "headline3",
"content": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s"
},
....
]
}
我还用 http://assemble.io/helpers/helpers-collections.html
中的 eachIndex 尝试了这个助手是的,我先安装了它 ;) (npm i handlebars-helpers --save-dev)
它只循环,但我没有得到索引的值,也没有得到 data.title 或 data.content
的值格雷戈尔
我发现了,它与 eachindex 一起使用,以获取您必须使用的索引 "this" 并获取 obj 的属性。 "item"
{{#eachIndex data}}
<div class="c_accordion__item c_accordion__item--active">
<header class="c_accordion__header">
<a href="js_item-{{this.index}}" class="link js_accordion_toggle">
<svg class="c_accordion__toggle-icon icon-arrow">
<use xlink:href="#arrow"></use>
<svg>
<h1 class="largest c_accordion__title">
{{item.title}}
</h1>
</a>
</header>
<div id="js_item-{{this.index}}" class="c_accordion__content">
<p>{{item.content}}</p>
<a href="#" class="link c_accordion__more">mehr lesen</a>
</div>
</div>
{{/eachIndex}}