创建了新闻模型:News.js
beforeCreate: async (model, attrs) => {
if (attrs['Date'] === null) {
model.set('Date', '2030-00-00 00:00:00+00');
}
}
当我创建帖子时,如果用户没有填写日期字段,我希望它自动预先填写。但是当我创建新页面时 model.set()
似乎没有效果。
最佳答案
我建议您使用beforeSave
函数。
beforeSave: async (model, attrs, options) => {
// detect if it's a creation or an update
if (options.method === 'insert') {
// statement for creation
if (attrs['Date'] === null) {
model.set('Date', '2030-00-00 00:00:00+00');
}
}
}
关于javascript - 无法在 beforeCreate Hook 中设置日期 - Strapi (beta14),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57411915/