【问题标题】:convert json object to htmlTable typescript将 json 对象转换为 htmlTable 打字稿
【发布时间】:2016-04-14 21:27:50
【问题描述】:

我想将我的 json 对象转换为表格,在 html 页面中显示。我使用打字稿来做到这一点。我有关于这个主题的任何信息,我刚刚在 javascript 中找到了一个解决方案:http://www.kodingmadesimple.com/2015/07/convert-json-data-html-table-jquery-datatables-plugin.html 它是一个例子还是一个解决方案? 感谢提前

【问题讨论】:

  • 您想将数据从一种格式转换为另一种格式,但您有什么问题?
  • 如何将 json 对象转换为 typescript 中的表格。

标签: typescript html-table jsonobject


【解决方案1】:

我认为您正在尝试学习如何使用打字稿进行编码?如果是这样,这可能会让你开始:

let input = {
  "data": [
    {
      "name": "Garrett Winters",
      "designation": "Accountant",
      "salary": "$170,750",
      "joining_date": "2011/07/25",
      "office": "Tokyo",
      "extension": "8422"
    }
 ]
}

function convert(data: typeof input) {
    let rows = data.data.map(d => `<tr><td>${d.name}</td></tr>`);
    return `<table>${rows}</table>`;
}

console.log(convert(input));

【讨论】:

  • 谢谢Corey,我会试试的。如果我从远程服务器检索 json 对象,我希望这是我应该使用的相同功能。
  • 输入来自哪里并不重要 :) 祝你好运!
猜你喜欢
  • 2018-10-10
  • 1970-01-01
  • 2020-12-15
  • 2021-07-24
  • 2019-11-04
  • 2018-09-18
  • 2017-03-22
  • 2017-02-11
  • 2020-12-27
相关资源
最近更新 更多