我试图在json数组内的json数组中使用dom-repeat内的dom-repeat.如何将第一个数组中的值传递给第二个dom-repeat?
为了说明,我有以下json数组加载正常:
"books": [
{
"title": "book1",
"slug": "b1",
"authors": ["author1","author2"],
"blurb": "Some text"
},
{
"title": "book2",
"slug": "b2",
"authors": ["author2","author3"],
"blurb": "some more text"
}]
Run Code Online (Sandbox Code Playgroud)
我正在迭代数组'books'并检索title和blurb.然后在下面,我希望列出每本书的两位作者,并且我还希望以/ slug/author(fi/b1/author1)的格式链接到每一本书.但是因为在第二个dom-repeat中我重新定义了"items",所以'slug'不再可用.我该怎么做?
<template>
<iron-ajax
auto
url="somelist.json"
handle-as="json"
last-response="{{someList}}"></iron-ajax>
<template is="dom-repeat" items="{{someList.books}}">
<paper-collapse-group>
<paper-collapse-item header$="{{item.title}}">
<p>{{item.blurb}}</p>
</paper-collapse-item>
<template is="dom-repeat" items="{{item.authors}}">
<a href$="/[[slug]]/[[item]]">{{item}}</a></div>
</template>
</paper-collapse-group>
</template>
</template>
Run Code Online (Sandbox Code Playgroud)
我也是Polymer的新手,谢谢你帮我学习!