【发布时间】:2019-08-02 06:57:39
【问题描述】:
我是 javascript 新手,我是在 vscode 中创建树视图的结构。
创建树视图时如果我将 JSON 直接传递给树它会创建一棵树,但是当我通过调用其余 API 传递数据时,不会创建树。
这是因为在从 rest api 检索数据之前,已将空数据变量传递给树。
如何解决?
提前致谢
class name {
gettreeItem(element){
//code
}
getChildren(element) {
if(element){
//some code here
}else{
return Promise.resolve(this.getDeps(restcall()))
}
restcall(){
var options = {
method: 'GET',
url: 'url',
headers:
{
Authorization :'Basic '+ Buffer.from('uid:pas').toString('base64')
}
};
return new Promise(function(resolve,reject){
request.get(options,function(err, resp, body){
if (err) {
reject(err);
} else {
return resolve(JSON.parse(body));
}
})
)
}
getDeps(JsonData){
//But here the Json Data is empty beacuse this function is called before the data is retrived from the rest api
}
}
【问题讨论】:
标签: node.js visual-studio-code vscode-extensions