0
我正在使用KeystoneJS版本4.0.0-beta.5,我試圖從我的某個模型中加載一些數據,這些數據由於某種原因返回null。我能夠爲我所有的其他模型加載數據,但是這個數據有點竅門,或者我忽略了一些東西。任何和所有的幫助將不勝感激。Keystone js findOne返回null
節點版本:6.11.2
型號代碼
var keystone = require('keystone');
var Types = keystone.Field.Types;
var Event = new keystone.List('Event', {
autokey: {
path: 'slug',
from: 'title',
unique: true
},
map: {
name: 'title'
}
});
Event.add({
title: {
type: String,
required: true
},
info: {
type: Types.Html,
wysiwyg: true,
height: 300
},
form: {
type: Types.Boolean
}
});
Event.defaultColumns = 'title';
Event.register();
路線/查看代碼
var keystone = require('keystone');
exports = module.exports = function (req, res) {
var view = new keystone.View(req, res);
var locals = res.locals;
// Set locals
locals.section = 'event';
locals.filters = {
detail: req.params.detail,
};
locals.data = {
details: [],
};
// load event data
view.on('init', function (next) {
var q = keystone.list('Event').model.findOne({
slug: locals.filters.detail,
})
q.exec(function (err, result) {
locals.data.detail = result;
console.log(result);
next(err);
});
});
// Render the view
view.render('detail');
};
謝謝,你是正確的我有一個錯字,但出人意料的是,在路線/ index.js。 – TylerMiller47
沒問題。很高興幫助。 –
@ TylerMiller47你是如何解決它的? –