如果我理解了這個問題,您正在尋找一種將隨機孩子分發到外層標籤DOM(Documentation)的方法。
這裏是你會怎麼做你的榜樣:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Outer-inner tags</title>
<base href="https://polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link href="polymer/polymer.html" rel="import">
</head>
<body>
<dom-module id="outer-tag">
<template>
<div>
<h1>The Outer Tag</h1>
<my-tag1></my-tag1>
<!-- Tell the <outer-tag> that something will go in here -->
<content select=".tag2"></content>
<my-tag3></my-tag3>
</div>
</template>
<script>
Polymer({
is: 'outer-tag'
});
</script>
</dom-module>
<dom-module id="random-tag">
<template>
<div>
<h2>Random Tag</h2>
<div>I'm a random component</div>
</div>
</template>
<script>
Polymer({
is: 'random-tag'
});
</script>
</dom-module>
<!-- Here's how to put them together -->
<outer-tag>
<random-tag class="tag2"></random-tag>
</outer-tag>
</body>
</html>
而不是」 .tag2" 你可以更一般寫‘隨機變量’。 select
屬性接受類CSS選擇器。