[英]How can i get the content from a promise object?? NodeJs
我想獲取文件夾的內容並調用此命令->“sftp.list (...)”。
但這將返回一個 Promise 對象。 我怎樣才能得到這個內容的名字??
我在下面附上了我的代碼,但我總是只得到所有信息。
var a = sftp.list(remoteFilename);
a.then(function(result){
console.log(a);
});
OUTPUT:
{ type: '-',
name: '14335.JSON',
size: 482369,
modifyTime: 1549637889000,
accessTime: 1549541207000,
rights: { user: 'rw', group: 'rw', other: 'rw' },
owner: 98438,
group: 840223400513 } ]
但我只想要文件中的名稱。
您的代碼不正確,要返回Promise
的結果,您必須使用return
如下:
var a = new Promise(function(res, rej){
// return promise
return sftp.list(remoteFilename);
}).then((result) => {console.log(result); // your result here});
如果你需要得到的返回值a
,使用await
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.