【发布时间】:2019-05-01 16:01:06
【问题描述】:
我正在尝试使用 Mammoth Node.js 包将文件从 Docx 转换为 HTML。 Mammoth 自述文件建议使用以下格式转换文件:
var mammoth = require("mammoth");
mammoth.convertToHtml({path: "path/to/document.docx"})
.then(function(result){
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
})
.done();
我已将此模板代码放在convertDoc 函数中,并且在调用convertDoc 函数后,我试图在代码的其他地方使用html 的值。
在convertDoc 函数中的任何位置放置return html 语句将不允许我使用存储的html,但是我可以将正确的html 内容输出到控制台。我需要关于如何从承诺之外返回/使用 html 变量的建议,谢谢。
【问题讨论】:
-
目前已经完成了哪些研究?你的经验水平如何?这已经被问过一两次了:stackoverflow.com/questions/37533929/…
-
你没有。你打电话给
.then承诺。您无法可靠地访问.then处理程序之外的数据。
标签: javascript node.js promise mammoth