我想在HTML中複製嵌入式SVG,在裏面重新定義它的ID。如何使用Closure庫在HTML中複製嵌入式SVG DOM?
例如,有一個HTML文件等
<html>
<body>
<div id="svgs">
</div>
<!-- Template -->
<div style="display:none;">
<svg xmlns="http://www.w3.org/2000/svg" width="181" height="59" id="type0svg">
<g style="display:inline" transform="translate(0,0)">
<text id="ph1" x="23.6" y="51.7">ph1</text>
<text id="ph2" x="105.1" y="51">ph2</text>
</g>
</svg>
</div>
</body>
</html>
和數據[{ph1:'placeholder1',ph2:'placeholder2'},{ph1:'apple',ph2:'orange'}]
。我想生成一個DOM像...
<html>
<body>
<div id="svgs">
<!-- {ph1:'placeholder1',ph2:'placeholder2'} -->
<svg xmlns="http://www.w3.org/2000/svg" width="181" height="59" id="type0svg1">
<g style="display:inline" transform="translate(0,0)">
<text id="ph1_1" x="23.6" y="51.7">placeholder1</text>
<text id="ph2_1" x="105.1" y="51">placeholder2</text>
</g>
</svg>
<!-- {ph1:'apple',ph2:'orange'} -->
<svg xmlns="http://www.w3.org/2000/svg" width="181" height="59" id="type0svg2">
<g style="display:inline" transform="translate(0,0)">
<text id="ph1_2" x="23.6" y="51.7">apple</text>
<text id="ph2_2" x="105.1" y="51">orange</text>
</g>
</svg>
</div>
<!-- Template -->
<div style="display:none;">
<svg xmlns="http://www.w3.org/2000/svg" width="181" height="59" id="type0svg">
<g style="display:inline" transform="translate(0,0)">
<text id="ph1" x="23.6" y="51.7">ph1</text>
<text id="ph2" x="105.1" y="51">ph2</text>
</g>
</svg>
</div>
</body>
</html>
注意下複製DOM所有的ID已經從「blahblah」到「blahblah_1」和「blahblah_2」重新定義。
這怎麼可以巧妙地使用Google閉包庫來完成?