【发布时间】:2018-08-01 02:09:29
【问题描述】:
我在服务器上有一个json文件,我的目的是根据json文件中的内容渲染一个表格,里面包含各种链接。
所以,pug 文件看起来像:
script.
$.getJSON("/db/url.json", function(json) {
console.log('DEBUG: from PUG: 1st URL in the JSON: ' + json[0].urls[0].url)
});
table.table
thead
tr
th.bg-primary.text-center.font-weight-bold.text-white(scope='col' colspan=7)
a.btn.btn-primary(data-toggle='collapse' href='#collapseExample' role='button' aria-expanded='true' aria-controls='collapseExample')
| Section-1
tbody.collapse.show(id='collapseExample')
tr
// Table contains will be got from the url.json file
url.json 文件可以很好地加载。但是我对如何使用这个 json 来填充 pug 模板中的表感到沮丧。你能提供什么想法吗?
jason 文件如下所示:
{
"name": "Section-1",
"desc": "Section-1",
"urls": [
{
"name": "Google",
"url": "http://www.google.com"
},
{
"name": "xxx",
"url": "http://10.182.44.97/"
}
]
}
【问题讨论】: