0

我试图在我的翡翠模板中使用一个 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} 但这给出了预期的字符非法错误。

4

1 回答 1

0

尝试美化您的 json 以获得最佳阅读效果。

杰森:

{"config":[
    {
        "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) 
       each data in config
         tr.rowlink
           td(href='#me')
             a(href='/dashboard/1') #{data.value.username}
           td
             a(href='/dashboard/1') #{data.value.filename}
           td
             a(href='/dashboard/1') #{data.value._id}
           td
             a(href='/dashboard/1') #{data.value._rev}
           td
             a(href='/dashboard/1') #{data.value.created_at}
           td
             a(href='/dashboard/1') #{data.id}
           td
             a(href='/dashboard/1') #{data.key}

呈现在:

<table class="table table-hover table-bordered table-striped">
  <thead>
    <tr>
      <th>#</th>
      <th>Dataset</th>
    </tr>
  </thead>
    <tbody data-provides="rowlink">
      <tr class="rowlink">
        <td href="#me"><a href="/dashboard/1">mike.merritt-holmes@bigdatapartnership.com</a></td>
        <td><a href="/dashboard/1">2321313123.txt</a></td>
        <td><a href="/dashboard/1">13788ea7cfd01e07bd5b393474036e28</a></td>
        <td><a href="/dashboard/1">1-81ab52488eae6dbef8265e4459cf6b96</a></td>
        <td><a href="/dashboard/1">2013-06-16T23:02:01.680Z</a></td>
        <td><a href="/dashboard/1">13788ea7cfd01e07bd5b393474036e28</a></td>
        <td><a href="/dashboard/1">mike.merritt-holmes@bigdatapartnership.com</a></td>
      </tr>
      <tr class="rowlink">
        <td href="#me"><a href="/dashboard/1">mike.merritt-holmes@bigdatapartnership.com</a></td>
        <td><a href="/dashboard/1">2321313123.txt</a></td>
        <td><a href="/dashboard/1">c1cf81b1fada50867f31bc11e952fe41</a></td>
        <td><a href="/dashboard/1">1-7153e8e92efe3dffd80a2ec363bd3fc2</a></td>
        <td><a href="/dashboard/1">2013-06-16T23:08:25.988Z</a></td>
        <td><a href="/dashboard/1">c1cf81b1fada50867f31bc11e952fe41</a></td>
        <td><a href="/dashboard/1">mike.merritt-holmes@bigdatapartnership.com</a></td>
      </tr>
    </tbody>
</table>
于 2013-06-18T00:58:56.147 回答