我正在尝试为sanity.io. 为此,我创建了以下文档:
export default {
name: 'news',
type: 'document',
title: 'News',
fields: [
{
name: 'title',
title: 'Title',
type: 'string',
},
...
{
name: 'author',
title: 'Author',
type: 'string',
},
...
],
preview: {
select: {
title: 'title',
subtitle: 'author',
}
}
}
这完全符合我在 Studio 中的要求。预览窗格中的部分显示title文档的标题,subtitle部分显示作者的姓名。
但是,如果我尝试author通过 using修改输出prepare,则它不再起作用。例如,看一下同一文档的以下变体:
export default {
name: 'news',
type: 'document',
title: 'News',
fields: [
{
name: 'title',
title: 'Title',
type: 'string',
},
...
{
name: 'author',
title: 'Author',
type: 'string',
},
...
],
preview: {
select: {
title: 'title',
author: 'author',
}
},
prepare(selection) {
const { author } = selection
return {
...selection,
subtitle: author && `${author} is the author`
}
}
}
预览字段已呈现,但该部分title中没有显示任何内容。subtitle但是,据我了解 - 这应该有效。我想知道为什么不。
有任何想法吗?