有一个控制器,其中有一个第三方库(是的,在 javastrip 上))))“dhtmlXTreeObject”,它绘制一棵树。他有自己的 ClickHandler。我正在为 click 函数中的全局变量赋值。但问题是变量没有更新。请帮助变量type1 type2。tonclick_checks 和 tonclick 函数。
我了解连接js库不好,tonclick_checks和tonclick在控制器范围内不起作用。但是如何更新变量。非常感谢您提前。
Import {
AfterViewInit, Component, DoCheck, EventEmitter, NgModule, NgZone, OnDestroy, OnInit,
Output
} from '@angular/core';
declare var dhtmlXTreeObject: any;
@Component({
selector: 'ngx-treemo',
styleUrls: ['./treemo.component.scss'],
templateUrl: './treemo.component.html',
})
export class TreemoComponent implements AfterViewInit, OnDestroy, OnInit, DoCheck {
type: ChartType;
graphic: boolean;
table: boolean;
chartTypes: ChartType[];
data: any;
modael1: any;
model: any;
modaltree: any;
type1: string;
type2: string;
newtype1: string;
newtype2: string;
options: any = {};
themeSubscription: any;
constructor(private http: HttpClient,
private theme: NbThemeService,
private zone: NgZone ) {
this.graphic = true;
this.table = false;
this.chartTypes = ['Bar', 'Line', 'Radar'];
this.type = 'Bar';
this.type1 = '523';
this.type2 = '1t1';
this.newtype1 = '523';
this.newtype2 = '0t';
}
onChange(deviceValue) {
}
ngOnInit(): void {
const myTree_checks = new dhtmlXTreeObject('treeboxbox_tree_checks', '100%', '100%', 0);
myTree_checks.setImagePath('../../../../assets/skinstree/web/imgs/dhxtree_web/');
myTree_checks.enableDragAndDrop(true);
myTree_checks.setOnClickHandler(this.tonclick_checks);
myTree_checks.enableMultiLineItems('100%');
const myTree1 = new dhtmlXTreeObject('treeboxbox_tree_types', '100%', '100%', 0);
myTree1.setImagePath('../../../../assets/skinstree/web/imgs/dhxtree_web/');
myTree1.enableDragAndDrop(true);
myTree1.setOnClickHandler(this.tonclick);
myTree1.enableMultiLineItems('100%');
}
tonclick_checks(id) {
this.type1 = id;
// console.log(this.type1);
}
tonclick(id) {
this.type2 = id;
// console.log(this.type2);
}
}
为了让 Agular 看到变化,你可以运行一个特殊的函数
ngZone.run
。例子:
把它
this
扔进处理程序不会有什么坏处,你可以这样尝试。如果它不起作用,你仍然可以尝试这个。