我正在尝试检索提交表单的日期。使用代码:
Template.SingleDailylog.helpers({
date: function(){
const id = FlowRouter.getParam('id');
if (id) {
profile = Dailylog.findOne({_id:id});
}
if (profile && profile.date) {
logDate = profile.date;
}
if (logDate) {
return moment(logDate).format('MM/DD/YYYY');
}
},
日期显示出来,但在控制台中它说:模板助手中的异常:ReferenceError:logDate 未定义在 Object.date ( http://localhost:3000/app/app.js?hash=b97240050e4c7c8657adb412270a5335856229b7:8546:5 )
如果我用 'name' 替换 'logDate':
Template.SingleDailylog.helpers({
date: function(){
const id = FlowRouter.getParam('id');
if (id) {
profile = Dailylog.findOne({_id:id});
}
if (profile && profile.date) {
name = profile.date;
}
if (name) {
return moment(name).format('MM/DD/YYYY');
}
},
我得到:弃用警告:提供的值不是公认的 RFC2822 或 ISO 格式。moment 构造回退到 js Date(),这在所有浏览器和版本中都不可靠。不鼓励使用非 RFC2822/ISO 日期格式,并将在即将发布的主要版本中删除。
像这样重写代码,以避免使用未声明的变量:
Template.SingleDailylog.helpers({
date: function(){
const id = FlowRouter.getParam('id');
if (id) {
const profile = Dailylog.findOne({_id:id});
if (profile && profile.date) {
return moment(profile.date).format('MM/DD/YYYY');
}
}
}
})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句