3
我有一個form-el
誰只是一個容器誰必須包裝所有兒童在div
與特定的類。我不想在每個表單元素中重複這個div
,而是想讓from-el
包裝它們。 我可以遍歷所有元素並將它們包裹在其他html標籤中嗎?實現這一裝飾元素從<content>
// Markup
<form-el>
<input-el label="name" type="text" />
<span>This must also be wrapped</span>
</form-el>
// Would produce
<form>
<div class="form-field">
<label>name</label>
<input type="text" name="name" />
</div>
<div class="form-field">
<span>This must also be wrapped</span>
</div>
</form>
// Where '<div class="form-field">' is produced by 'from-el'
非常感謝。但是當我嘗試包裹聚合物元素時,它只顯示第一個。 http://jsbin.com/sadexakoyuco/1/edit – 2014-09-02 08:41:37
沒有自定義元素可以是無效的,喵喵,你不能使用' '你必須使用' '。 –
2014-09-02 19:05:23
@ScottMiles如何/何時可以得到包裝?由於模板是異步標記和分佈的,因此''this.updateWrappers();''很簡單''setTimeout'足夠後,我無法立即獲得對this.shadowRoot.querySelectorAll(「div」)的引用? 在簡化的情況下,它的工作原理是http://jsbin.com/zuxiqo/1/edit,但它足以避免任何競爭條件嗎? – tomalec 2015-02-24 00:55:54