试图将一个Polymer元素附加到另一个Polymer元素中

vdegenne

我有一个v-fire聚合物:

<script>
    Polymer({
        is: 'v-fire',

        properties : {
            onFire: {
                type : String,
                reflectToAttribute: true
            }
        },

        firing: function () {
            this.fire('fire');
        }
    })
</script>

我希望能够在我的Polymer元素中的任何地方使用它,以使其触发内部函数,以使其执行诸如update之类的特定任务,因此在v-fire调用时它们将全部更新firing

例如,我创建了一个新对象进行测试:

<script>
    Polymer({
        is: 'fire-tester',

        _updateContent: function () {
            alert('I get updated');
        }
    });
</script>

index.html中


<link rel="import" href="/components/fire-tester/fire-tester.html">
<body>
<fire-tester id="fire-tester"></fire-tester>
<script>
(function () {

    var ft = document.getElementById('fire-tester');

    // make a global v-fire Polymer
    var vfire = document.createElement('v-fire');
    // custom callback of the Polymer's that will include the v-fire
    vfire.onFire = '_updateContent';

    /**
     * And here, I try to insert the v-fire in the fire-tester Polymer
     */
    Polymer.dom(ft.root).insertBefore(
        vfire,
        Polymer.dom(ft.root).childNodes[0]
    );

    // the dom is pretty neat, fire-tester contains v-fire with the custom on-fire callback

    // then I try to fire the event
    vfire.firing(); // but nothing happen


});
</script>

这是行不通的,因为我相信将v-fire插入fire-tester中时不会对其进行处理有没有办法告诉Polymer处理dom块,就像在本地DOM中声明它一样?

齐克斯

看来您正在错误地接近事件系统。您想要的是fire-tester在检测到firev-fire元素上的事件时对它运行方法,对吗?这就是我将其组合在一起的方式:

v-fire.html

<script>
  Polymer({
    is: 'v-fire',

    firing: function() {
      this.fire('fire');
    }
  });
</script>

fire-tester.html

<script>
    Polymer({
      is: 'fire-tester',

      listeners: {
        'fire': '_updateContent'
      },

      _updateContent: function () {
        alert('I get updated');
      }
    });
</script>

index.html

<fire-tester id="fire-tester"></fire-tester>
<script>
  (function(){
    var ft = document.getElementById('fire-tester');

    var vfire = document.createElement('v-fire');

    Polymer.dom(ft.root).insertBefore(
        vfire,
        Polymer.dom(ft.root).childNodes[0]
    );

    vfire.firing();
  })();
</script>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将列表(元素)附加到另一个列表中,按字母给出一个元素

如何将列表中的匹配元素附加到另一个列表?

如何将现有的 html 元素附加到另一个元素?

将一个列表的每个命名元素附加到另一个列表的相同命名元素

如何使用使用绑定属性的指令将一个元素附加到另一个元素?

指向另一个元素的href在Polymer中不起作用

将列表的所有元素分别附加到python中另一个列表的所有元素

如何将多维数组中的元素附加到另一个多维数组的每个元素

将一个xml元素添加到另一个xml中

如何将重复的元素附加到同一父元素的另一个元素中的不同父元素中

如何将一个列表的所有元素附加到另一个列表?

将DatePicker附加到另一个UI元素

将另一个numpy数组附加到numpy数组作为数组,而不是元素

将张量附加到另一个张量的每个元素

无法使用 konva 将变压器附加到另一个类的元素

将列表的元素附加到迭代器的左侧或右侧到另一个列表

使用powershell将另一个子元素附加到xml

如何在 Swift 中从另一个视图控制器将元素附加到数组中

Javascript将一个元素添加到另一个没有id的元素中

C:将数组的所有元素添加到另一个元素中

使用 jQuery 复制 div 并附加到一组元素中的另一个元素

使用来自另一个 webapp 的 Polymer 3.0 自定义元素

在已附加的另一个元素内附加一个元素

单击时,将元素克隆到变量并将其附加到另一个元素

将一个文件附加到另一个文件中

将一个元组附加到另一个元组 python 中

如何通过jQuery中的另一个附加元素访问附加元素

如何将一个列表中的元素添加到另一个列表中?

如何将一个列表中的元素添加到另一个列表?