gpt4 book ai didi

dart - 查询自定义元素,返回为 UnknownElement

转载 作者:行者123 更新时间:2023-12-03 02:45:15 25 4
gpt4 key购买 nike

我定义了一个自定义元素 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>

然后我查询聊天 View :

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

上一行导致以下异常:

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

有没有一种方法可以通过获取 ChatView 对象而不是 UnknownElement 的方式来查询我的自定义元素?

最佳答案

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

最终的 ChatView chatView = query("#chat").xtag;

关于dart - 查询自定义元素,返回为 UnknownElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18580053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com