Javascript 例外:未定义猛犸象
我正在尝试将猛犸象npm库与meteor集成 使用“导入”命令时, 从“猛犸象”导入{mammoth}越来越多了 未捕获的TypeError:无法读取未定义的属性“bind” 使用命令时, 猛犸象:任何越来越多了 例外:未定义猛犸象 我使用的代码是Javascript 例外:未定义猛犸象,javascript,meteor,npm,node-modules,mammoth,Javascript,Meteor,Npm,Node Modules,Mammoth,我正在尝试将猛犸象npm库与meteor集成 使用“导入”命令时, 从“猛犸象”导入{mammoth}越来越多了 未捕获的TypeError:无法读取未定义的属性“bind” 使用命令时, 猛犸象:任何越来越多了 例外:未定义猛犸象 我使用的代码是 this.readFileInputEventAsArrayBuffer(事件,函数(arrayBuffer)){ 猛犸象 .convertToHtml({arrayBuffer:arrayBuffer}) .then(函数(结果:任意){ var
this.readFileInputEventAsArrayBuffer(事件,函数(arrayBuffer)){
猛犸象
.convertToHtml({arrayBuffer:arrayBuffer})
.then(函数(结果:任意){
var html=result.value;//生成的html
var messages=result.messages;//任何消息,例如转换期间的警告
//log('html:'+html);
document.getElementById(“输出”).innerHTML=html;
var elements=document.getElementById(“输出”).children;
控制台日志(元素);
log(JSON.stringify(elements));
console.log(elements.length);
对于(var i=0;i });代码>如果查看mammoth npm包的源代码,您将看到没有“mammoth”或默认导出。但是,它会导出每个方法,因此您可以这样做:
import {convertToHtml} from "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();
这应该可以做到:)试试看这是否有效:导入'mammoth/mammoth.browser'代码>(浏览器构建)
或者,如果您可能希望在前端执行此操作,那么您可以使用,然后在html页面上包含以下脚本,并在运行时执行此操作。(将文档转换为html并呈现)
- 如本文所示->
要包括的脚本:
- demo.js->
- mammoth.browser.min.js->
希望这有帮助。尝试这样导入:
从“mammoth/mammoth.browser”导入{convertToHtml}代码>
在componet.ts文件中:
import {convertToHtml} from "mammoth/mammoth.browser";
convertToHtml({ arrayBuffer: arrayBuffer })
.then(function(result){
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
})
.done();
以上代码在angular 9中为我工作。如何将猛犸象库导入页面?请尝试从“猛犸象”导入猛犸象代码>?@Alex,当我使用它导入时,得到这个未捕获的类型错误:无法读取未定义的属性“bind”。我的疑问是meteor中是否支持猛犸象库的集成/使用?请注意我的示例中没有{
和}
example@Raven,我正在通过尝试以下操作导入mammoth库,import{mammoth}from“mammoth”;从“猛犸”进口猛犸;猛犸象:任何;var猛犸象=需求(“猛犸象”)你好,米克尔,谢谢你的回答。但即便如此,我也面临以下错误<代码>未捕获类型错误:无法在MeteoInstall.node_modules.mammoth.lib.docx.files.js(modules.js?hash=ee5060b…:83272)的fileEvaluate(modules runtime.js?hash=637cb12…:191)的require(modules runtime.js?hash=637cb12…:116)的MeteoInstall.node_modules.mammoth.lib.docx-reader.js(modules runtime.js?hash=637cb12…:116)读取未定义的属性(modules.js?hash=ee5060b…:82091)在需要时评估(modules runtime.js?hash=637cb12…:191)在需要时评估(modules runtime.js?hash=637cb12…:116)
在meteroinstall.node_modules.mammoth.lib.index.js(modules.js?hash=ee5060b…:81954)在需要时评估(modules runtime.js?hash=637cb12…:191)(modules runtime.js?hash=637cb12…:116)在meteoinstall.client.imports.app.app.component.js(app.component.ts:3)在fileEvaluate(modules runtime.js?hash=637cb12…:191)在fileEvaluate(modules runtime.js?hash=637cb12…:116)在meteoinstall.client.imports.app.index.js(index.ts:1)在fileEvaluate(modules runtime.js?hash=637cb12…:191)at require(modules runtime.js?hash=637cb12…:116)
at meteoinstall.client.main.js(main.ts:5)at fileEvaluate(modules runtime.js?hash=637cb12…:191)at require(modules runtime.js?hash=637cb12…:116)at demo.collection.ts:4
在这方面有其他方法/帮助吗?