0

我正在将 聚合物用户界面卡从 JS 移植到 Dart。

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

在 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>

我们的 Dart 端口看起来像

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

app-element有 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>

聚合物用户界面卡(在 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 的问题,还是我做错了什么?

4

1 回答 1

1

由于事件重定向target,不再可能在没有上下文的情况下谈论事件。

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

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

于 2014-03-24T03:21:00.637 回答