【问题标题】:how to display data in html table?如何在html表格中显示数据?
【发布时间】:2018-02-21 21:14:58
【问题描述】:

我有这样的对象:my object

我想在 html 表格中显示这些数据。 我得到了所有这些值:

Object.entries(this.state.urls).forEach(([property, value]) => {
  console.log(value)
})

现在看起来像: current state

如何将所有这些元素放在一个表中?

【问题讨论】:

  • 似乎不是对象。看起来更像是一个字符串数组。
  • 如果您提供 1) 实际输入的代码 sn-p(我可以粘贴到我的编辑器中 - 我不是指 console.log 打印的内容),您的问题将更容易回答和 2) 您期望的输出的代码 sn-p。或者,也许您可​​以编写一个失败的单元测试,其中包含一个正确的断言来显示您想要什么?

标签: javascript arrays html-table


【解决方案1】:

this.state.urls 似乎是一个数组数组,您想将每个数组中的所有 url 合并为一个数组。

尝试关注

var urls = [].concat.apply([], this.state.urls); 

【讨论】:

    猜你喜欢
    • 2011-01-21
    • 1970-01-01
    • 2012-08-15
    • 2020-12-02
    • 2019-09-13
    • 1970-01-01
    • 2013-11-22
    • 2023-04-01
    • 2013-07-08
    相关资源
    最近更新 更多