首页 > 解决方案 > 以预先存在的方法承诺

问题描述

目前我有以下代码:

  let getThemeId = getMainThemeId();
  getThemeId.then(id => {
    themeId = id;
    csi.evalScript("exportAIHtml()", function(result){
      alert(result);
    });//main()
  });

getTheme 是一种返回值的方法,然后我可以运行 .then。第一部分工作正常。csi.evalScript 是一种预建在我正在使用的模块中的方法。它返回一个回调,所以我可以使用结果。为了代码清晰,我想在另一个中使用结果。

我试过这个:

  let getThemeId = getMainThemeId();
  getThemeId
  .then(id => {
    themeId = id;
    return csi.evalScript("exportAIHtml()", function(result){
      return (result);
    })
    .then(result => alert(result));

那里的警报显示为未定义,因此显然它没有等待它完成执行。这是否必须包含在新的承诺中才能使其按预期工作?它不应该只是链接它并继续吗?

标签: javascript

解决方案


推荐阅读