2017-02-03 41 views
2

在聚合物1.0我重複<option>標籤<select>標籤內是這樣的:如何重複聚合物2.x中的<option>標籤?

<select> 
 
    <template is="dom-repeat" items="{{items}}"> 
 
    <option value$="[[item]]">[[item]]</option> 
 
    </template> 
 
</select>

但在聚合物2.X它建議使用<dom-repeat>標籤:

<select> 
 
    <dom-repeat items="{{items}}"> 
 
    <template> 
 
     <option value$="[[item]]">[[item]]</option> 
 
    </template> 
 
    </dom-repeat> 
 
</select>

但這不起作用。那麼如何在Polymer 2中重複<option>標籤?

+1

由於DOM重複元素沒有完全完成,有很多報告的錯誤是propably更好地與合作是=「DOM重複」。你可以在github上公佈這個問題,但我不確定,如果它是bug。必須有一些解決方法 –

回答

4

此問題與one reported for <dom-repeat> inside <table>類似。

用於現在的解決方法是使用 「混合模式」,其中2.0 <dom-repeat>包裝了<template is="dom-repeat">

<select> 
    <dom-repeat items="[[items]]"> 
    <template is="dom-repeat" items="[[items]]"> 
     <option value="[[item]]">[[item]]</option> 
    </template> 
    </dom-repeat> 
</select> 

codepen

UPDATE: @DocDude(阿瑟·伊文思從聚合物隊) noted in Slack使用<template is="dom-repeat">將仍然支持裏面的聚合物2.0元素。您只需使用元素外部的element包裝(例如,在index.html中)。

slack discussion

從聚合物核心團隊@KevinShaaf也已經confirmed this in GitHub

github comment

+0

[聚合物2.0關於頁面](https://www.polymer-project.org/2.0/docs/about_20#type-extension)指出,「蘋果已經表示它不會執行'是' ,我們不會鼓勵它的使用,以避免無限期地依賴於自定義元素polyfill「。所以我認爲這可能是做到這一點的短期正確方式(我接受這是正確的答案),但我希望將來會有更多標準化的方法來做到這一點。 – jehna1

+0

@ jehna1蘋果公司不會支持本地*,但polyfills將在此期間繼續支持它(而''中的bug正在進行中)。您最初質疑的2.0代碼實際上是符合標準的,因此在修補程序登陸後這些代碼就可以工作。 – tony19