代码之家  ›  专栏  ›  技术社区  ›  Günter Zöchbauer

指针事件目标始终是最外层的Polymer元素

  •  0
  • Günter Zöchbauer  · 技术社区  · 11 年前

    我正在移植 polymer-ui-card 从JS到Dart。

    不同之处在于,在我们的项目中(按照惯例),我们有一个额外的聚合物元素(app元素),它包含了整个应用程序。

    在JavaScript中,它看起来像

    <body unresolved>
      <div id="cards">
        <polymer-ui-card swipeable>Swipe Me!</polymer-ui-card>
        <polymer-ui-card swipeable>Swipe Me!</polymer-ui-card>
        <polymer-ui-card></polymer-ui-card>
        <polymer-ui-card swipeable>Swipe Me!</polymer-ui-card>
        <polymer-ui-card></polymer-ui-card>
      </div>
      ..
    </body>
    

    我们的达特港看起来像

    <body unresolved>
      <app-element></app-element>
    </body>
    

    app元素 具有body标记在JS中的内容

    <polymer-element name='app-element'>
      <template>
        <div id="cards">
          <polymer-ui-card swipeable>Swipe Me!</polymer-ui-card>
          <polymer-ui-card swipeable>Swipe Me!</polymer-ui-card>
          <polymer-ui-card></polymer-ui-card>
          <polymer-ui-card swipeable>Swipe Me!</polymer-ui-card>
          <polymer-ui-card></polymer-ui-card>
        </div>
      </template>
      ..
    <polymer-element>
    

    聚合物ui卡 (JS和Dart相同)

    <polymer-element name="polymer-ui-card" attributes="swipeable noCurve"
    on-trackstart="{{trackStart}}" on-track="{{track}}" on-trackend="{{trackEnd}}" on-flick="{{flick}}">
    

    这里的问题是所有指针事件的目标都是 <app-element> 而不是 <polymer-ui-card> 元素。

    这是故意的吗,或者这是一个可能只属于Dart的问题,或者我做错了什么?

    1 回复  |  直到 11 年前
        1
  •  1
  •   Scott Miles    11 年前

    因为 event retargeting 不再可能谈论 target 没有上下文的事件。

    事件侦听器的注册位置决定了事件对象上标识的DOM节点的范围。

    如果打开事件侦听器 <app-element> 它将始终是目标,因为它在文档范围中没有子级。