gpt4 book ai didi

javascript - angular2 组件内的 dhtmlx

转载 作者:太空狗 更新时间:2023-10-29 18:24:44 26 4
gpt4 key购买 nike

我想在我的 Angular2 组件中使用 dhtmlx onEmptyClick 事件,我想在其中调用我的组件的函数 changewall(),但出现错误:

this.changeWall is not a function

如果我将 changewall() 放在 scheduler.attachEvent 之外,主体工作正常。为什么会这样?

不起作用:

 scheduler.attachEvent("onEmptyClick", function (date, e ){
console.log('clickBefore');
this.changeWall(1511305200000);
console.log('clickAfter');
});

这有效:

 this.changeWall(1511305200000);
scheduler.attachEvent("onEmptyClick", function (date, e ){
console.log('clickBefore');
console.log('clickAfter');
});

完整代码:

import {Component, OnInit, AfterViewInit, HostListener} from '@angular/core';
import {WallService} from "../../services/wall.service";
declare var scheduler:any; //hide errors
@Component({
moduleId: module.id,
selector: 'big-calendar',
templateUrl: 'calendar2.component.html',
styleUrls: ['calendar2.component.scss']
})
export class Calendar2Component implements AfterViewInit {
private wallInstance: any;
events: any;
constructor(private _wall: WallService) {

}

@HostListener('click', ['$event'])
onClick(e) {
// this.refreshCalendar();
}

refreshCalendar(){
let date = new Date(scheduler.getState().date);
let month = date.getMonth() + 1;
let year = date.getFullYear();
// scheduler.clearAll();

scheduler.attachEvent("onEmptyClick", function (date, e ){
console.log('clickBefore');
this.changeWall(1511305200000);
console.log('clickAfter');
});

this._wall.getCalendarEvents(month, year).subscribe((data: any)=>{
console.log(data);
let i = 0, events = [];

while(i < data.events.length){
events.push({
holder: "t", //userdata
room: "1" ,
text: data.events[i].name,
start_date: data.events[i].start,
end_date: data.events[i].end +1
});

i++;
}
console.log(events);
scheduler.init('scheduler_here',new Date(),"month");

scheduler.parse(events,"json");
});
}


ngAfterViewInit(): void {
scheduler.config.touch = "force";
this.refreshCalendar();
// scheduler.parse([
// {id:1, text:"Meeting", start_date:"04/11/2016 14:00",end_date:"14/12/2016 17:00"}
// ],"json");
}

changeWall(timestamp){
// let timestamp = new Date(date).getTime();
// console.log(timestamp);
this.wallInstance = this._wall.getInstance();
this.wallInstance.timeChanger(timestamp);
}
}

最佳答案

scheduler.attachEvent("onEmptyClick", function (date, e ){

应该是

scheduler.attachEvent("onEmptyClick", (date, e ) => {

并更改其他使用 function

的地方

参见 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

关于javascript - angular2 组件内的 dhtmlx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47240959/

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