最初填充TreeView并实例化TreeView."刷新"按钮调用自定义刷新功能以收集更新的数据.这些新信息存储在上下文中.globalState()
ctmInfrastructureProvider.refresh();
不会更新TreeView.我还添加了事件侦听器.
export class CtmInfrastructureProvider implements vscode.TreeDataProvider<number> {
private _onDidChangeTreeData: vscode.EventEmitter<number | null> = new vscode.EventEmitter<number | null>();
readonly onDidChangeTreeData: vscode.Event<number | null> = this._onDidChangeTreeData.event;
.
.
.
constructor(private context: vscode.ExtensionContext) {
let ctmInfrastructureCacheTmp: any = context.globalState.get('ctmInfrastructureCache');
this.refresh();
}
.
.
.
}
以下是我的刷新功能:
let ctmInfrastructureRefreshEntry = vscode.commands.registerCommand(
'ctm.infrastructure.refreshEntry',
async () => {
ctmInfrastructureDicsovery = discoverCtmInfrastructure(); context.globalState.update('ctmInfrastructureCache',JSON.parse(ctmInfrastructureDicsovery));
ctmInfrastructureProvider.refresh();
}
);
context.subscriptions.push(ctmInfrastructureRefreshEntry);
TreeDataProvider刷新()
refresh(offset?: number): void {
this.parseTree();
}
private parseTree(): void {
this.text = this.ctmInfrastructureCache;
this.tree = json.parseTree(this.ctmInfrastructureCache);
}
我错过了什么?