我正在尝试将动态月份和年份添加到我的基础电子邮件模板中。我尝试在year.js
中的/src/helpers/
中添加年份 - {{year}}
,如下所示:
http://foundation.zurb.com/forum/posts/37160-insert-current-yeardate-in-html
但是当我提到module.exports = function() {
return new Date().getFullYear();
}
时它不起作用。
我的代码是:
let args = "[{id:1049105, api_url:'', timestamp: 2017-07-12T00:34:36.000Z},{id:993221, api_url:'', timestamp: 2017-07-12T00:34:18.000Z}]"
let splitArgs = args.split('},')
// Create an Array of parsed Objects
let objs = splitArgs.map(arg => {
// remove whitespace
let cleanArg = arg.trim()
// Remove enclosing [ { } ] characters
if (arg.startsWith('[')) {
cleanArg = cleanArg.substr(1, arg.length)
}
if (cleanArg.startsWith('{')) {
cleanArg = cleanArg.substr(1, arg.length)
}
if (cleanArg.endsWith(']')) {
cleanArg = cleanArg.substr(0, arg.length - 1)
}
if (cleanArg.endsWith('}')) {
cleanArg = cleanArg.substr(0, arg.length - 1)
}
// Remove any quotations and then split each of the properties out
let props = cleanArg.replace(/[\']+/, '').split(',')
// For each prop, get the value and assign it to the new object
// that will be returned by reduce()
return props.reduce((obj, prop) => {
let splitIndex = prop.indexOf(':')
let key = prop.substr(0, splitIndex)
let val = prop.substr(splitIndex + 1, prop.length)
if (key.toLowerCase() === 'timestamp') {
obj[key] = (new Date(val))
} else {
obj[key] = val
}
return obj
}, {})
})
console.log(objs.map(obj => { return obj.id })) // [1049105, 993221]
想知道我是否遗漏了一些明显的东西。
答案 0 :(得分:1)
发布此内容后立即找到修复程序。您所要做的就是停止观看CMD/Ctrl + C
重新启动您的npm服务器npm start
并按照预期的方式运行。