我有一个结果变量,它是一个对象数组。我将结果变量从我的 javascript 文件传送到我的主路由文件。我正在尝试渲染我的页面以显示模板 ejs 文件中每个对象的列表。我能够很好地列出所有内容,但是列表以 [object object] 的形式出现,而不是对象中的实际单词。如何让它在我的模板文件中显示为字符串?
这是我的路由文件:
app.get('/announcement', function(req,res){
var getAnnouncements = require('../public/javascripts/announcement.js'); //Load the module, get the name of the script file
//define the functions here
var onSpreadsheetSuccess = function (results) { //result is announcementArray
//add results list to template);
res.render('announcement', {title: "Announcement page", results: results});
}
getAnnouncements.loadSheet(onSpreadsheetError, onSpreadsheetSuccess); //call the function from script with the parameters passed
})
Run Code Online (Sandbox Code Playgroud)
这就是我在模板 ejs 文件中所做的:
<ul>
<% results.forEach(function(result){ %>
<li><%= result %></li>
<% }); %>
</ul>
Run Code Online (Sandbox Code Playgroud) 我正在使用moment.js插件来显示我的应用程序中条目的更新时间.所有条目都具有unix时间戳格式的time_updated属性.如何使用此时间格式并将其与当前时间进行比较.我查看了文档,发现了这个:
moment([2015, 0, 29]).fromNow()
Run Code Online (Sandbox Code Playgroud)
但是没有在哪里解释括号之间的数字是什么意思或参数应该是什么格式.
以下是我正在使用的代码
var timestamp = clientObject.topics_projects[x].date_updated;
var then = moment.unix(timestamp).format("HH:mm");
var now = moment(currentDate).format("HH:mm");
Run Code Online (Sandbox Code Playgroud)
那么如何才能获得当时和现在之间的时差?例如,阅读"几秒钟前"或"3分钟前".