2017-06-15 79 views
0

我有像下面如何獲得聚合物定製元素的innerDOM?

<custom-element> 
    <img src="path1"> 
    <img src="path2"> 
    <img src="path3"> 
    <img src="path4"> 
</custom-element> 

現在我想在一個單獨的div

我在custom-element模板

<div class="image-wrapper"> 
    <content select="img"></content> 
</div> 

上面的代碼試圖這樣來顯示每個圖像的聚合物定製元素使所有圖像在單個格中爲image-wrapper,如下所示

<div class="image-wrapper"> 
    <img src="path1"> 
    <img src="path2"> 
    <img src="path3"> 
    <img src="path4"> 
</div> 

但我想在個別image-wrapper每個圖像如下圖所示

<div class="image-wrapper"> 
    <img src="path1"> 
</div> 
<div class="image-wrapper"> 
    <img src="path2"> 
</div> 
<div class="image-wrapper"> 
    <img src="path3"> 
</div> 
<div class="image-wrapper"> 
    <img src="path4"> 
</div> 

我怎樣才能做到這一點?

回答

0

作爲一個快速的答案,

<custom-element> 
    <img src="path1"> 
</custom-element> 
<custom-element> 
    <img src="path2"> 
</custom-element> 
<custom-element> 
    <img src="path3"> 
</custom-element> 
<custom-element> 
    <img src="path4"> 
</custom-element> 

你可能把它包這樣,

<template is="dom-repeat" items="[[paths]]" as="path"> 
    <custom-element> 
     <img src="[[path]]"> 
    </custom-element> 
</template> 

假設路徑是一個數組。

paths = [ 
    "path1", 
    "path2", 
    "path3", 
    "path4", 
]; 
相關問題