gpt4 book ai didi

Polymer 中的 Javascript(没有以正确的方式定位)

转载 作者:行者123 更新时间:2023-12-02 16:59:49 26 4
gpt4 key购买 nike

所以我刚刚开始使用Polymer,我想在这个元素中构建一个自定义的SoundCloud播放器。不知怎的,我不断收到以下错误:

Uncaught Error: SC.Widget function should be given either iframe element or a string specifying id attribute of iframe element.

这应该意味着我没有以正确的方式定位 iframe,但我想不出其他方法来做到这一点(因为几乎 4 小时了)。

= 我的问题是为什么 var iframe = $(".iframe"); 不定位 iframe。我在 Polymer 之外尝试过,效果很好。

breaker-stream.html:

<polymer-element name="breaker-stream" attributes="url">
<template>
<iframe class="iframe" width="100%" height="450" scrolling="no" frameborder="no" src="{{url}}"></iframe>
<script>
var iframe = $(".iframe");
var widget = SC.Widget(iframe);
</script>
</template>
<script>
Polymer('breaker-stream', {
url: ""
});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="https://w.soundcloud.com/player/api.js"></script>
</polymer-element>

最佳答案

  1. 您不能使用 jquery $像在主文档中一样访问影子根目录中的元素。这是有详细记录的,请尝试搜索。
  2. 推杆<script>模板中的标签是一个坏主意,请将元素脚本放在原型(prototype)对象中(在 Polymer() 内)。
  3. 输入 <script> 也是一个坏主意。 <polymer-element>里面。它们放在那里时不会做任何特殊的事情,而应该放在该元素之外。

这是一个工作示例( http://jsbin.com/xujole/4/edit ):

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Polymer</title>

<!-- web components polyfill for non-Chrome -->
<script src="//www.polymer-project.org/components/platform/platform.js"></script>

</head>
<body>

<breaker-stream url="http://api.soundcloud.com/users/1539950/favorites"></breaker-stream>

<!-- from here down could be in an import -->

<!-- need this to make Polymer elements -->
<link rel="import" href="//www.polymer-project.org/components/polymer/polymer.html">
<!-- don't load this twice -->
<script src="https://w.soundcloud.com/player/api.js"></script>

<polymer-element name="breaker-stream" attributes="url" block>
<template>
<iframe id="frame" width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url={{url}}"></iframe>
</template>
<script>
Polymer({
url: "",
ready: function() {
this.widget = SC.Widget(this.$.frame);
}
});
</script>
</polymer-element>

</body>
</html>

关于Polymer 中的 Javascript(没有以正确的方式定位),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25838661/

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