尝试修改 getVersion 像这样:
getVersion
getVersion:async function(i){ var returnedLatestVersion; return new Promise((resolve, reject) => { App.contracts.Trades.deployed().then(async function(instance){ await instance.getLatestVersionOfTrade.call(i).then(function(a){ returnedLatestVersion = a; console.log("test:"+returnedLatestVersion+",a:"+a); resolve(returnedLatestVersion); // here you return your result as a promise }).catch(function(err){ console.log(err) reject(err); // here you reject the promise in case of error }) console.log("test2="+returnedLatestVersion); }) }) }
你也可以返回instance.getLatestVersionOfTrade.call(i)`的结果,这也会返回一个promise。但我认为使用“解决方案”可以让您更清楚地知道您返回的是什么。