2017-06-15 53 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", 
];