我试图用聚合物1.0实现一个网站。 我有一个自定义元素my-greeting,里面有一些模板重复。
我想做什么,而且我不知道如何做到这一点,就是得到一个名为TARGET的字符串,如下所示:
/constantPath/folder1/aaa.jpg
/constantPath/folder1/bbb.jpg
/constantPath/folder2/aaa.jpg
/constantPath/folder2/bbb.jpg
所以一般字符串是: / constantPath / {{repeat1.id}} / {{repeat2.id}}。jpg
我该怎么做?
这是我的代码:
<dom-module id="my-greeting">
<template>
<template is="dom-repeat" items="{{repeat1}}">
<template is="dom-repeat" items="{{repeat2}}">
Target : <iron-image src="TARGET"></iron-image>
</template>
</template>
</template>
<script>
Polymer({
is: 'my-greeting',
ready: function() {
this.repeat1 = [
{id: 'folder1'},
{id: 'folder2'}
];
this.repeat2 = [
{id: 'aaa'},
{id: 'bbb'}
];
}
}
);
</script>
感谢。
答案 0 :(得分:2)
你走了:
<dom-module id="my-greeting">
<template>
<template is="dom-repeat" items="{{repeat1}}" as="folderOne">
<template is="dom-repeat" items="{{repeat2}}" as="folderTwo">
Target : <span>{{getTarget(folderOne, folderTwo)}}</span></br>
</template>
</template>
</template>
<script>
Polymer({
is: 'my-greeting',
ready: function() {
this.repeat1 = [
{id: 'folder1'},
{id: 'folder2'}
];
this.repeat2 = [
{id: 'aaa'},
{id: 'bbb'}
];
},
getTarget: function(folderOne, folderTwo){
return "/constantPath/"+folderOne.id+"/"+folderTwo.id;
},
}
);
</script>
</dom-module>