- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在我的主干应用程序中使用 YoutTube 的 Iframe API,但我不确定我的方法是否正确。
var VideoView = Backbone.Marionette.ItemView.extend({
initialize: function(){
var that = this;
this.currentVideoIndex = 0;
Events.on("changeVideo", function (target){
that.changeVideo(target.id);
});
_.bindAll(this);
this.player = new window.YT.Player('player', {
videoId: this.model.videos[0],
width: 700,
height: 400,
events: {
'onStateChange': that.onPlayerStateChange
},
playerVars: {
autoplay: 1,
controls: 1,
modestbranding: 1,
rel: 0,
showInfo: 0
}
});
},
onPlayerStateChange: function(event) {
if(event.data == 0 ){
this.currentVideoIndex = this.currentVideoIndex + 1;
this.player.loadVideoById(this.model.videos[this.currentVideoIndex]);
},
changeVideo: function(event){
var newIndex = this.model.videos.indexOf(event);
this.currentVideoIndex = newIndex;
this.player.loadVideoById(event);
}
});
这是我用来创建新的 YT.Player 对象的代码。第一次我的 View 初始化时一切正常,并且“changeVideo”方法按预期工作。但是,如果我转到另一个页面并使用 Iframe 播放器返回该页面,第一个视频将按预期开始,但是当我尝试更改视频后出现错误。
Uncaught TypeError: Cannot call method 'postMessage' of null
在这两种情况下,我的 OnPlayerState 更改方法都按预期工作 - 当前视频结束后下一个视频开始播放。
这是错误的屏幕截图(如果有帮助的话): https://www.dropbox.com/s/zmdo80yux4h7pg8/Screenshot%202013-12-04%2013.13.35.png
您还可以在此处查看实时网站 http://gorlla.herokuapp.com/ ,如果您只是单击其中一门类(class)并单击转到类(class)后您将无法转到下一个视频,并且如果您打开控制台您将看到“Uncaught TypeError: Cannot call method 'postMessage' of null “信息。
最佳答案
首先,与此无关的是,您定义了“that”两次。
其次,为什么不在您离开页面时尝试在播放器上调用 .destroy,因为(如果我理解正确的话)每次您回来时它都会重新初始化。
我不得不说,我见过的大多数与此类似的错误都与 Chrome 管理 iFrame 状态的方式有关。例如,如果 iFrame 未附加到 DOM,则它将为 null。但不确定这在其他浏览器上如何工作。您是否从其他地方手动删除 DOM 元素?我遇到了类似的问题,发现此页面很有帮助:
https://groups.google.com/forum/#!topic/youtube-api-gdata/bThZuUg51qg
总而言之,尝试事先进行一些清理并使用 .destroy。
关于javascript - 具有主干的 Youtube IFrame API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20382882/
我开发了一个 jquery &backbone.js 网络应用程序。 一个组件有一个 html 表,该表后面是一个主干.js 集合。 此集合中的任何更改都应该导致 html 表的更新,所以我写 thi
我创建了一个由 HTTP Basic 保护的无状态 RESTful API。 在客户端,我将创建一个登录表单,向/auth-check 发送请求以检查凭据,并根据状态代码,将这些凭据存储在客户端并使用
我已经有一个具有经典结构的存储库 /branches /current /beta /tags /1.0 /2.0 /trunk 我想从当前的编辑器切换到 Eclipse,但我应该创建
我正在阅读 red bean SVN book ,它说要像这样布局主干、分支和标签文件夹: $ svn list file:///var/svn/multi-project-repo project-
当特定属性发生变化时,Backbone 模型触发自定义事件的好方法是什么? 到目前为止,这是我得到的最好的: var model = Backbone.Model.extend({ initi
我想避免在 Backbone.Collection 上的每个“添加删除重置”事件上重新渲染。 所以在 Backbone.View 中我可能有: this.listenTo(this.collectio
这一定是我没有正确理解的东西。 我有一个名为 Album 的 Backbone 模型: var Album = Backbone.Model.extend({ idAttribute: "_id",
假设我有一个具有一堆 bool 属性的 Backbone 模型: Car = Backbone.Model.extend({}); car_one = new Car({ a_c: true,
我从 collection.fetch() 调用中得到一个包含多个嵌套对象的对象。有没有办法解析这些子对象并将它们作为单独的模型传递到集合中? 这是我要返回的数据的示例。从服务器获取时,我想将它作为
有一个脚本(js),我希望在它上面运行,比如$(document).ready()。有一种方法可以在模板(例如 home_tpl.html)文件中编写脚本。但我确信这不是一个好方法。 我正在从主干 V
配合我正在尝试从主干集合中包含的所有模型中获取更大的属性。 举个例子: App.Models.Example = Backbone.Model.extend({ defaults: {
我遇到这样一种情况,我需要为一个人保存几个对象,但一次保存一个对象,并且在获取时,我将所有对象作为一个数组以及该人的信息。 这是模型的样子: //Model for one save { pe
我开始阅读一些 Backbone 教程,发现一件让我惊讶的事情。为什么模型是在 View 内部创建的?如果我想要一个模型有两个不同的 View (我认为 MVC 的用途)怎么办?假设我需要一个模型 C
我使用backbone.js 创建了一个小型网站。它托管在 IIS 7 中。 路由: routes: { "/": "index", "": "ind
我现在正在构建一个 View ,当我单击 .organization 链接时,我想触发我的编辑事件,但是单击此元素时,没有任何内容被触发,我无法理解为什么。 这是构建我的 View 的代码, App.
我有一些全局参数,我想在每次调用集合上的提取时发送这些参数...我的问题是我不想声明 data: { ... }每次我获取。 有没有一种方法可以在 Collection 本身内部提供默认参数,并可以添
Backbone 新手在这里。我想开始在 Web 应用程序上使用主干(后端是 Ruby on Rails),直到现在它的客户端功能还很少(一些用于执行 slideToggles 的 jquery,以及
我想知道是否有办法从其中一个模型中获取对集合的引用。例如,如果下面集合中的任何人以某种方式知道属于一个集合或多个集合。 Fiddle (function() { window.App = {
如何在集合获取中阻止模型的解析功能? $(function() { var Task = Backbone.Model.extend({ url : function(
我们一直在使用位于文件夹根目录中的存储库,一切都很好。然而,自从网站上线后,我们需要对一些工作进行分支,但由于缺少主干而无法这样做。 我的问题是,如何在当前目录结构中创建一个主干并将所有当前内容移动到
我是一名优秀的程序员,十分优秀!