- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不能在我的函数中调用任何函数或变量
我有 onReady 事件(youtube api 事件)
同样,当我执行 console.log(this) 时,结果在函数内部未定义
这是我的 typescript 代码
isOn :boolean = false;
createPlayer(): void {
return new window['YT'].Player(this.youtube.playerId, {
height: this.youtube.playerHeight,
width: this.youtube.playerWidth,
playerVars: {
rel: 0,
showinfo: 0
},
events: {
'onReady': this.onPlayerReady,
'onStateChange': this.state,
}
});
}
public state(event) {
this.isOn = true; //here is the problem and the result is not defined
}
//this class from ionic 2
最佳答案
你应该像这样使用箭头函数:
isOn :boolean = false;
createPlayer(): void {
return new window['YT'].Player(this.youtube.playerId, {
height: this.youtube.playerHeight,
width: this.youtube.playerWidth,
playerVars: {
rel: 0,
showinfo: 0
},
events: {
'onReady': () => { /* Put your logic here! */ }
'onStateChange': () => { this.isOn = true; /* Now it should work! */ }
}
});
}
当使用常规函数时,this 关键字引用函数本身,但是当使用箭头函数时,this 属性不会被覆盖并且仍然引用组件实例(您定义 navCtrl 属性的地方) .
关于javascript - 无法调用 - 这个 - 在 youtube api 事件中(onReady 等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874827/
我使用jwplayer 7企业版,同时使用新API格式的onReady方法,但onReady事件并非一直触发。 我在控制台中也没有看到任何错误。 以下链接是示例播放器,请帮助解决此问题。 http:/
首先让我声明,当我打开一个新的浏览器页面并输入我的 Web 服务器的 URL 时,下面的代码工作正常,当我重新加载页面(F5 或 Ctrl-R)时它也工作。 它只能部分工作但是如果我重新打开一个关闭的
我正在实现异步加载脚本的功能。 XHR 完成后,我将代码插入文档并调用回调方法。回调方法使用动态加载的代码。 我想知道的是,在附加脚本被解析之前我的回调会被调用吗?我是否需要使用 window.onR
我是 Sencha 的新手。 现在我正在使用 Sencha architect 来开发我的应用程序。为了添加功能,我在我的应用程序中使用了一个开源扩展。扩展的文档告诉我们将一段代码添加到 onRead
通常,您在 HTML 源代码的 head 元素中拥有所有框架(脚本和 css),并在渲染页面时加载它们。例如。我想加载 jQuery 和 boostrap 它看起来像这样:
我使用厚盒在模式窗口中显示一些 html 内容。 我知道厚盒组件被标记为“未维护,请尝试其他组件”,但我没有选择使用它。 html 内容是通过记录的“AJAX 内容”方法加载的: cl
我采用了一个定义了多个对象文字的项目 - 主要用于构建代码。顺便说一句,不是全职前端开发人员。问题是其中一些是使用 jQuery onready 事件定义的,而另一些则在外部。至少可以说,这似乎确实有
下面是我的js文件和两个div,我不明白为什么html2不起作用,我得到“sendMessage未定义”。有人可以向我解释一下...或者只是一个解释链接。 谢谢 $(function() {
我正在 Ocaml 中使用 TCP/IP 套接字开发一个协议(protocol),我有兴趣实现事件驱动的方法。基本上,我想制作事件处理函数,只要套接字接收到新数据或关闭或打开就会调用。 是否可以在 O
我想打开网页自动填写登录信息。下面给出了我的 main.js 插件代码。我有 uname 和 upass 变量。我想在插件打开选项卡时使用这些填写登录表单。 var uname="username
我尝试调用 new SP.ClientContext.get_current() 但在我这样做的时候我得到一个 Cannot read property 'get_current' of undefi
这是我的代码:加载后,它应该调用事件--“onReady”,然后在浏览器控制台中打印出“My player is onReady”。但它没有显示。基本上,这是一个非常简单的 YouTube API 使
我对新的 Android API21 有疑问,特别是 VoiceInteractorService。 我想在 API21 中使用新的热词检测。如果我按下一个按钮,“google”这个词的热词检测应该开
HighCharts 是否有任何 onReady(或类似的)就绪事件? 目前HighCharts仅提供addSeries、click、load、redraw、selection 用于图表对象 ( ht
我正在删除我的 Rails/views/show.html.erb 中使用的 Javascript 中的全局变量 我正在使用的 javascript 是 var App = {}; App.UserS
我想测量在每个页面中运行整个 $().ready() 范围需要多长时间。 为了分析特定函数,我只需在相关部分的开头设置一个新的 Date() 变量,然后检查到达相关部分的末尾需要多长时间。 测量整个
我正在学习 JS 中的一些高级主题,并且我正在尝试理解一些东西。 我已经编写了一个 VueJS 应用程序,我需要在 Vue 本身之外公开一些来自 Vue 的数据和可能的方法。我正在使用 vuex。 这
在 ExtJs 中,我们有一个名为 Ext.onReady() 的页面加载事件,它在 window.onload 之后被调用,因为它被注册到 onload 并被调用。所以基本上我们可以找到的最后一个事
使用 IE8 和 headjs 我有一个模板 header 模板文件,其中包含 head.ready(function(){}) 。此页面已加载我的所有页面。 在某些页面上,我的代码中有调用 head
具有三个选项卡按钮。 (tab_button_1、tab_button_2、tab_button_3) tab_page 加载 - 选择 tab_button_1。 但是。 main_page 链接
我是一名优秀的程序员,十分优秀!