在下面的代碼中,當我嘗試以編程方式訪問它或在Chrome中檢查DOM時,模板#欄的內容「Foo」始終爲空。有人能解釋爲什麼嗎?帶模板內容的聚合物自定義元素
一般而言,如何將外部元素中定義的模板提供給內部元素,以便內部元素可以訪問內容並有條件地克隆或導入內容?
我正在使用聚合物0.4.2。
<polymer-element name="x-inner" noscript>
<!--
How can I access the content "Foo" of <template>Foo</template>,
So that I can import/clone it here?
Using <content> moves the template from x-outer to x-inner,
but the template's .content property is empty, instead of 'Foo' as I expected.
-->
<content></content>
</polymer-element>
<polymer-element name="x-outer" noscript>
<template>
<x-inner>
<!--
How can I pass a template to a custom element?
I don't want the contents of this template to be rendered
here in x-outer, but instead conditionally rendered by x-inner
-->
<template id="bar">Foo</template>
</x-inner>
</template>
</polymer-element>
<x-outer></x-outer>
感謝您的詳細的解答,特別是示出了在聚合物基本的HTML模板和模板之間的差異。我想我會仔細看看TemplateBinding.js的內部 – 2014-10-09 23:57:21