聚合物 - 如何使用绑定创建元素 [英] Polymer - how to create element with binding

查看:104
本文介绍了聚合物 - 如何使用绑定创建元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用绑定属性创建聚合物自定义元素。

I need to create polymer custom element with binding attribute.

<foo-bar baz="{{qux}}"></foo-bar>

没关系。
但它必须动态创建(tagName作为属性传递)。我试试这个

It's OK. But it must be created dynamically (tagName passed as an attribute). I try this

Polymer({
    ready: function() {
        var element = document.createElement(this.tagName);
        element.setAttribute('baz', '{{qux}}');
        this.$.placeholder.appendChild(element);
    }
});

但它不起作用。我该怎么办?

But it does not work. How can I do that?

推荐答案

你可以用 injectBoundHTML()

<div id="container"></div>

...

this.injectBoundHTML('<foo-bar baz="{{qux}}"></foo-bar>', this.$.container);

尚未记录,但更多信息在这里: https://github.com/Polymer/docs/issues/607

It's not documented yet, but more info is here: https://github.com/Polymer/docs/issues/607

这篇关于聚合物 - 如何使用绑定创建元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆