在Keystone JS中,可以使用以下字段类型来保存对象数组:
Relationship
字段类型来保存对象数组,并且定义对象之间的关系。Select
字段类型来保存对象数组,并且定义可选的选项值。Text
字段类型来保存对象数组的文本数据。JSON
字段类型来保存对象数组的JSON数据。const { Keystone } = require('@keystonejs/keystone');
const { Relationship } = require('@keystonejs/fields');
const keystone = new Keystone(/* keystone config */);
keystone.createList('Post', {
fields: {
title: { type: Text },
authors: { type: Relationship, ref: 'Author', many: true },
},
});
keystone.createList('Author', {
fields: {
name: { type: Text },
posts: { type: Relationship, ref: 'Post', many: true },
},
});
在上述示例中,我们定义了两个模型:Post
和Author
。Post
模型有一个authors
字段,它使用了Relationship
字段类型,并且通过ref
属性指向了Author
模型,表示一篇文章可以有多个作者。Author
模型有一个posts
字段,它也使用了Relationship
字段类型,并且通过ref
属性指向了Post
模型,表示一个作者可以有多篇文章。
推荐的腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云