gpt4 book ai didi

javascript - Node : Dynamically create html from an object

转载 作者:行者123 更新时间:2023-11-30 19:52:12 25 4
gpt4 key购买 nike

我正在使用 API 获取 NodeJS 中对象形式的内容。这个对象有一个标题、文本和几个表格。现在我想遍历这个对象,从中创建 HTML 并将其传递到我的数据库。在基本 JS 中,我会简单地遍历对象元素并使用“document.createElement(..)”一个一个地创建 HTML 元素。但是,正如我发现的那样,“文档”在 NodeJS 中不可用。

所以我想知道是否有类似的方法来做到这一点?我看到了我只使用字符串的选项,例如:var elem = '<div>' + text + '</div>'; .但是,我想知道是否还有其他更好的选择来处理这个问题。

最佳答案

jsdom有解决办法

jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node.js. In general, the goal of the project is to emulate enough of a subset of a web browser to be useful for testing and scraping real-world web applications.

关于javascript - Node : Dynamically create html from an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54363688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com