以编程方式创建特殊的Polymer-Element [英] Programmatically create special Polymer-Element

查看:96
本文介绍了以编程方式创建特殊的Polymer-Element的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下html的聚合物元素:

I have got a polymer-element with following html:

<polymer-element name="tab-bar">
  <template>
    <button>Hello</button>
    <template repeat="{{item in items}}">
      <div>This element is {{ item }}</div>
    </template>
  </template>
  <script type="application/dart" src="tab_bar.dart"></script>
</polymer-element>

基本的dart类如下:

The underlying dart class looks as follows:

import 'package:polymer/polymer.dart';

@CustomTag('tab-bar')
class TabBar extends PolymerElement {
  List items;

  TabBar(List<String> items) {
    this.items = toObservable(items);
  }
}

使用以下方法,无法以编程方式添加元素:

With the following approach, it isn't possible to programmatically add the element:

query('body').children.add(createElement(new TabBar(['One','Two','Three'])));

那么,现在我该如何以编程方式添加这种聚合物元素,并在构造函数中设置列表呢?

So now, how can I add such a polymer element programatically and also set the list in the constructor?

推荐答案

从聚合物0.8.5开始,您可以使用类似的构造函数

As of polymer 0.8.5 you can use constructor like

new Element.tag('tag-bar');

另外,.xtag和.host也不再(host == this this)

also, no more .xtag and no more .host (host == this now)

信用额转到 Seth Ladd ,他在聚合物邮件列表中对此进行了解释

credits go to Seth Ladd who explained this on polymer mailing list

这篇关于以编程方式创建特殊的Polymer-Element的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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