【问题标题】:Querying a custom element, is returned as UnknownElement查询自定义元素,返回为 UnknownElement
【发布时间】:2013-09-05 23:11:18
【问题描述】:

我已经定义了一个自定义元素 chat-view 并让它显示在页面上:

<!DOCTYPE html>

<html>
  <head>
    <title>index</title>
     <script src="packages/polymer/boot.js"></script>
    <link rel="import" href="chat_view.html">
  </head>

  <body>   
    <chat-view id="chat">
    </chat-view>

    <script type="application/dart" src="index.dart"></script>
  </body>
</html>

然后我查询聊天视图:

final ChatView chatView = query("#chat");

上一行导致以下异常:

Exception: type 'UnknownElement' is not a subtype of type 'ChatView' of 'chatView'.

有没有办法以获取 ChatView 对象而不是 UnknownElement 的方式查询我的自定义元素?

【问题讨论】:

  • 在 JS 中有一个触发 polymer-project.org/polymer.html#WebComponentsReady 的“WebComponentsReady”事件。不确定 Dart 端口有什么。在元素升级并准备就绪之前,您将无法查询 DOM,因此建议在立即开始工作之前等待此事件。

标签: dart dart-webui polymer dart-polymer


【解决方案1】:

经过一番挖掘,我发现自定义元素实例是通过UnknownElement的xtag属性访问的。

final ChatView chatView = query("#chat").xtag;

【讨论】:

    猜你喜欢
    • 2016-08-15
    • 2019-07-23
    • 2016-04-15
    • 1970-01-01
    • 2017-07-31
    • 2015-01-15
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    相关资源
    最近更新 更多