Skip to content Skip to sidebar Skip to footer

How To Specify Multiple Fields In Keystone.js List Map?

Want to know how to specify multiple fields in Keystone.js List Map. For example, based on the Keystone Data Model documentation: http://keystonejs.com/docs/database/ var keystone

Solution 1:

I can achieve the multiple key map by Genereated Value:

The example model Post can be written as below:

varkeystone=require('keystone'),Types=keystone.Field.Types;varPost=newkeystone.List('Post', {
    autokey: { path:'slug', from:'newKey', unique:true },
    map: { name:'newKey' },
    defaultSort:'-createdAt'
});Post.add({newKey: { type:Types.Text, watch:true, noedit:true, value:function(callback) {
        varauthor=this.author;vartitle=this.title;keystone.list('User').model.findOne({_id:this.author.toString()}).exec(function(err, u) {
            if(err) {
                callback(err, "unknown")
            } else {
                varr="("+u.name.first+""+u.name.last+")-"+title;callback(null, r)
            }
        });
    }},title: { type:String, required:true, index:true, initial:true },state: { type:Types.Select, options:'draft, published, archived', default:'draft' },author: { type:Types.Relationship, ref:'User', index:true, initial:true },createdAt: { type:Date, default:Date.now },publishedAt:Date,image: { type:Types.CloudinaryImage },content: {
        brief: { type:Types.Html, wysiwyg:true, height:150 },
        extended: { type:Types.Html, wysiwyg:true, height:400 }
    }
});Post.defaultColumns='title, state|20%, author, publishedAt|15%'Post.register();

For the above model, when creating Post, it will initially ask for Title and Author:

enter image description here

This will create a Post like this, with mutliple fields as a map:

enter image description here

Post a Comment for "How To Specify Multiple Fields In Keystone.js List Map?"