【发布时间】:2015-03-20 13:12:44
【问题描述】:
我想在我稍后传递给 List.add 的架构对象中使用从 keystone.List 构造函数中的 autokey 插件生成的相同值。
这更准确地说是我想要做的:
var Thing = new keystone.List('Thing', {
autokey: { path: 'slug', from: 'title', unique: true }
});
Thing.add({
image: {
type: Types.LocalFile,
dest: 'public/images/things/'+Thing.slug,
prefix: '/images/things/'+Thing.slug+'/',
format: function( ThingDoc, file ) { return '<img src="/images/things/'+ThingDoc.slug+'/'+file.filename+'" style="max-width:300px" />' }
}
});
所以这当然行不通。以后如何在我的架构中重新使用自动键入的 slug 值?
顺便说一句,引用在“格式”函数中起作用,因为当调用该函数时,它可以通过实例化模型提取存储的值。
【问题讨论】:
标签: mongoose keystonejs mongoose-plugins