Search code examples
node.jstemplatesswig-template

Node js swig object display


{% for item in list %}
        <div class="todo_item">
            <span class="hidden_id">{{ item.id }}</span>
            <div class="item_title"> {{item.title}}</div>
            <div class="item_tooltip">date {{item.dateCreated}}</div>
            <div class="item_tooltip">{{ item|json_encode }}</div>
        </div>
        {% endfor %}

The {{ item|json_encode }} output is :

{"_id":"53f82ab44f3254584e970684","username":"k4","title":"kkk3323","__v":0,"dateCreated":"2014-08-23T05:46:28.326Z","status":true}

The {{item.dateCreated}} displays [object Object].

And I use {{ item.id }}, not the {{ item._id }} because of the [object Object] output.


Solution

  • Your {{item.dateCreated}} is a Date object, I'm assuming... which is why it's showing as [object Object]. If you want to format it as a date, there's a date filter for this exact purpose: http://paularmstrong.github.io/swig/docs/filters/#date