Javascript代码 我想在媒体回调函数中使用this.progressbar
class CatMusicPlayer {
constructor(url,playPauseBtn,progressbar,progressTime,durationTime) {
this.url = url;
this.playPauseBtn = playPauseBtn;
this.progressbar = progressbar;
this.progressTime = progressTime;
this.durationTime = durationTime;
new Media(url,null,this.logerror,function(mediaStatus){
/*
i want to use this.progressbar,
but in this block "this" reffers to Media class.
Media is kind of another class similar to CatMusicPlayer
*/
});
}
答案 0 :(得分:2)
将'QuerySet' object has no attribute 'name'
的值缓存到另一个变量this
然后使用它const _thisMP = this;
或者在您的情况下,您甚至可以直接致电_thisMP.progressbar();
,因为它可以访问
progressbar()
答案 1 :(得分:0)
class CatMusicPlayer {
constructor(url,playPauseBtn,progressbar,progressTime,durationTime) {
this.url = url;
this.playPauseBtn = playPauseBtn;
this.progressbar = progressbar;
this.progressTime = progressTime;
this.durationTime = durationTime;
let self = this;
new Media(url,null,this.logerror,function(mediaStatus){
self.progressbar();
});
}