将 Asp.net 中使用的 jsgantt-improved Gantt 图表转换为 Blazor 的示例代码如下:
将所有的全局变量定义改为类的成员变量,例如:
var g = null;
// 更改为类中的成员变量
this.g = null;
将所有使用的全局函数改为私有方法,例如:
function parseXMLString(xmlDocStr) {
var xmlDoc;
if (window.DOMParser) {
var parser = new window.DOMParser();
xmlDoc = parser.parseFromString(xmlDocStr, "text/xml");
}
else { // Internet Explorer
xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(xmlDocStr);
}
return xmlDoc;
}
// 更改为私有方法
parseXMLString(xmlDocStr) {
var xmlDoc;
if (window.DOMParser) {
var parser = new window.DOMParser();
xmlDoc = parser.parseFromString(xmlDocStr, "text/xml");
}
else { // Internet Explorer
xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = "false";
xmlDoc.loadXML(xmlDocStr);
}
return xmlDoc;
}
import { HttpClient } from '@angular/common/http';
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
declare var GanttImproved: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
@ViewChild('ganttChart', { static: true }) ganttChart: ElementRef;
constructor(private http: HttpClient) { }