我试图在我的翡翠模板中使用一个 json 对象,由于某种原因,我似乎无法取消它,所以我循环的每个项目都看到了每一个字符而不是对象变量。我已经尝试了我能想到的一切,但无济于事。请帮忙。
这是我的js:
db.view('dataset/byUsername', { key: req }, function (err, doc)
{
datasets = doc;
var config = {
'user': req,
'datasets': jQuery.parseJSON(datasets),
'dashboards': []
};
res.render('welcome', { config: jQuery.parseJSON(config) });
});
我的 json 数据集对象如下所示:
:[{"id":"13788ea7cfd01e07bd5b393474036e28","key":"mike.merritt-holmes@bigdatapartnership.com","value":{"_id":"13788ea7cfd01e07bd5b393474036e28","_rev":"1-81ab52488eae6dbef8265e4459cf6b96","jsonType":"datasetconfig","username":"mike.merritt-holmes@bigdatapartnership.com","filename":"2321313123.txt","size":"1312313213","created_at":"2013-06-16T23:02:01.680Z","updated_at":"2013-06-16T23:02:01.680Z"}},{"id":"c1cf81b1fada50867f31bc11e952fe41","key":"mike.merritt-holmes@bigdatapartnership.com","value":{"_id":"c1cf81b1fada50867f31bc11e952fe41","_rev":"1-7153e8e92efe3dffd80a2ec363bd3fc2","jsonType":"datasetconfig","username":"mike.merritt-holmes@bigdatapartnership.com","filename":"2321313123.txt","size":"1312313213","created_at":"2013-06-16T23:08:25.988Z","updated_at":"2013-06-16T23:08:25.988Z"}}]
我的玉模板如下所示:
table.table.table-hover.table-bordered.table-striped
thead
tr
th #
th Dataset
tbody(data-provides="rowlink")
if (config.datasets)
for item,key in config.datasets
tr.rowlink
td(href='#me')
a(href='/dashboard/1') item.username
td
a(href='/dashboard/1') item.filename
我试过 #{config.datasets} 但这给出了预期的字符非法错误。