i have a custom footer-bar (tabfooter) that creates a set of buttons with inline SVG inside of it (for styling reasons its inline).
I didnt want to put the complete code for all SVG into the attributes, so i just hand over some ids, which are used by the component to determine the paths on its own.
<custom-tabfooter values="{" ids ":["A ","B ","C ","D "]}"></custom-tabfooter>
The component then takes the object with the ID array inside and uses it for repeating the DOM elements that are needed:
<dom-module id="custom-tabfooter">
<template>
<template is="dom-repeat" items="{{values.ids}}">
<button id$="[[addButtonID(item)]]" class$="[[addButtonClass(item)]]">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<!--<use xlink:href="../assets/img/svg/A-icon.svg#path"></use>-->
<use xlink:href$="[[replaceSVGPath(item)]]"></use>
</svg>
</button>
</template>
</template>
<script>
Polymer({
is: "custom-tabfooter",
properties: {
values: Array
},
ready: function() {
console.log(this.values.ids);
},
addButtonID: function(item) {
return "btn-footer-icon-" + item;
},
addButtonClass: function(item) {
return "btn-footer-icon btn-" + item;
},
replaceSVGPath: function(item) {
return "../assets/img/svg/" + item + "-icon.svg#path";
}
});
</script>
</dom-module>
This works as intended. But when it comes to the SVG i get confused. There is one line commented out:
<!--<use xlink:href="../assets/img/svg/A-icon.svg#path"></use>-->
This line actually works. Though its only loading a single static SVG by using the internal tag.
When i try to load dynamic SVG content, it fails silently as no errors are thrown nor any SVG has loaded:
<use xlink:href$="[[replaceSVGPath(item)]]"></use>
The output however is pretty similar:
<use xlink:href="../assets/img/svg/A-icon.svg#path"></use>
<use class="style-scope custom-tabfooter" xlink:href="../assets/img/svg/A-icon.svg#path"></use>
The only visible difference is that polymer adds classes to that element.
Anyone an idea?
thanks.Rob
A workaround is to add the attribute statically in addition to the binding
<use xlink:href="" xlink:href$="[[replaceSVGPath(item)]]"></use>
Polymer has issues creating the attribute, if it already exists it can update it just fine.
This is an issue with Polymer. SVG uses namespaced attributes. To set them properly, you need to call setAttributeNS, but Polymer's attribute bindings aren't namespace-aware, so they can't set these attributes.
This is filed as issue #3060.
来源:https://stackoverflow.com/questions/33146886/polymer-1-0-dynamic-use-xlinkhref-inside-template-not-working-properly