如何让未发布的Polymer属性表现得像已发布的属性?
未发表的obj属性:
<dynamic-attributes obj="[object Object]"></dynamic-attributes>
发布的obj属性:
<dynamic-attributes obj="{{ {'hello':'world'} }}"></dynamic-attributes>
答案 0 :(得分:1)
诀窍是在Polymer获得它们之前获取属性。这可以在created
生命周期回调中完成。
它可以与injectBoundHTML
一起使用来呈现
<polymer-element>
<script>
Polymer({
created: function () {
var name = 'seriously-effect-' + this.type;
// get mustache bindings before they get parsed and bound
var instanceDecl = '<' + name + ' ';
var attrs = this.attributes;
for(var i = 0, l = attrs.length, attr; attr = attrs[i], i < l; ++i){
instanceDecl += attr.name + '="' + attr.value + '" ';
}
instanceDecl += '></' + name + '>';
//then parse attributes somehow... and stamp the template
this.templateInstance.model.injectBoundHTML(instanceDecl, parsedAttributesModel);
},
});
</script>
</polymer-element>