小编JCo*_*ier的帖子

如何摆脱 Node.js 中的 [Object: null prototype]?

有没有办法摆脱[Object: null prototype]终端中的 ,所以它只会显示{title: 'book'}

console.log(req.body);在 node/express.js 中做

终端

node.js express

14
推荐指数
3
解决办法
2万
查看次数

查找任何祖先元素中是否存在 HTML 数据属性

我引用了一个元素,baseElement,并且我想查找某个 HTML 数据属性是否存在于其祖先之一的某处,并在找到时获取它的值。如果该属性存在于多个祖先上,我只想要最密切相关的那个上的属性。

我设计了一个循环,由父母启动并检查该属性是否存在。假设的第一个父级baseElement不为空。

let currentElement = baseElement.parentElement;
let foundAttribute = false;
let valueOfAttribute = null;

do {
  foundAttribute = currentElement.hasAttribute('html-attribute');
  if (foundAttribute) {
    valueOfAttribute = currentElement.getAttribute('html-attribute');
  } else {
    currentElement = currentElement.parentElement;
  }
} while (!foundAttribute && currentElement);
Run Code Online (Sandbox Code Playgroud)

我想看看是否有一种更有效、更雄辩或更易于编码的方式来做到这一点。请,只有纯 JavaScript 答案。

html javascript

0
推荐指数
1
解决办法
174
查看次数

标签 统计

express ×1

html ×1

javascript ×1

node.js ×1