middleware/_modelIndex.js
function (cb) {

                // loop through each record
                async.each(Object.keys(records), function (index, recordDone) {

                    // store the rendered content into a separate property
                    records[index]['rendered'] = {};

                    // loop through each field
                    async.each(Object.keys(req.linz.model.list.fields), function (field, fieldDone) {

                        // Skip this field if we have a falsy value
                        if (!req.linz.model.list.fields[field]) {
                            return fieldDone();
                        }

                        // If we have a reference field, data has been pre-rendered.
                        // Let's grab it from there.
                        if (req.linz.model.schema.tree[field] && req.linz.model.schema.tree[field].ref) {

                            // The default value, but could be replaced below if the conditions are right.
                            records[index]['rendered'][field] = records[index][field];


                            // Do we have a rendered result for this field in this particular record?
                            // Support multiple types ref fields.
                            if (refColData[field].rendered && records[index][field] && refColData[field].rendered[linz.api.model.getObjectIdFromRefField(records[index][field]).toString()]) {

                                records[index]['rendered'][field] = refColData[field].rendered[linz.api.model.getObjectIdFromRefField(records[index][field]).toString()];

                            }

                            // We're all done here.
                            return fieldDone();

                        }

                        // This will only execute if we don't have a ref field.

                        let args = [];

                        // value is not applicable for virtual field
                        if (!req.linz.model.list.fields[field].virtual) {
                            args.push(records[index][field]);
                        }

                        args.push(mongooseRecords[index]);
                        args.push(field);
                        args.push(req.linz.model);
                        args.push(function (err, value) {

                            if (!err) {
                                records[index]['rendered'][field] = value;
                            }

                            return fieldDone(err);

                        });

                        // call the cell renderer and update the content with the result
                        // val, record, fieldname, model, callback
                        req.linz.model.list.fields[field].renderer.apply(this, args);

                    }, function (err) {

                        recordDone(err);

                    });


                }, function (err) {

                    cb(err);

                });

            }
function (cb) {

                // loop through each record
                async.each(Object.keys(records), function (index, recordDone) {

                    // store the rendered content into a separate property
                    records[index]['rendered'] = {};

                    // loop through each field
                    async.each(Object.keys(req.linz.model.list.fields), function (field, fieldDone) {

                        // Skip this field if we have a falsy value
                        if (!req.linz.model.list.fields[field]) {
                            return fieldDone();
                        }

                        // If we have a reference field, data has been pre-rendered.
                        // Let's grab it from there.
                        if (req.linz.model.schema.tree[field] && req.linz.model.schema.tree[field].ref) {

                            // The default value, but could be replaced below if the conditions are right.
                            records[index]['rendered'][field] = records[index][field];


                            // Do we have a rendered result for this field in this particular record?
                            // Support multiple types ref fields.
                            if (refColData[field].rendered && records[index][field] && refColData[field].rendered[linz.api.model.getObjectIdFromRefField(records[index][field]).toString()]) {

                                records[index]['rendered'][field] = refColData[field].rendered[linz.api.model.getObjectIdFromRefField(records[index][field]).toString()];

                            }

                            // We're all done here.
                            return fieldDone();

                        }

                        // This will only execute if we don't have a ref field.

                        let args = [];

                        // value is not applicable for virtual field
                        if (!req.linz.model.list.fields[field].virtual) {
                            args.push(records[index][field]);
                        }

                        args.push(mongooseRecords[index]);
                        args.push(field);
                        args.push(req.linz.model);
                        args.push(function (err, value) {

                            if (!err) {
                                records[index]['rendered'][field] = value;
                            }

                            return fieldDone(err);

                        });

                        // call the cell renderer and update the content with the result
                        // val, record, fieldname, model, callback
                        req.linz.model.list.fields[field].renderer.apply(this, args);

                    }, function (err) {

                        recordDone(err);

                    });


                }, function (err) {

                    cb(err);

                });

            }
function ( cb ) { // loop through each record async . each ( Object . keys ( records ) , function ( index , recordDone ) { // store the rendered content into a separate property records [ index ] [ 'rendered' ] = { } ; // loop through each field async . each ( Object . keys ( req . linz . model . list . fields ) , function ( field , fieldDone ) { // Skip this field if we have a falsy value if ( ! req . linz . model . list . fields [ field ] ) { return fieldDone ( ) ; } // If we have a reference field, data has been pre-rendered. // Let's grab it from there. if ( req . linz . model . schema . tree [ field ] && req . linz . model . schema . tree [ field ] . ref ) { // The default value, but could be replaced below if the conditions are right. records [ index ] [ 'rendered' ] [ field ] = records [ index ] [ field ] ; // Do we have a rendered result for this field in this particular record? // Support multiple types ref fields. if ( refColData [ field ] . rendered && records [ index ] [ field ] && refColData [ field ] . rendered [ linz . api . model . getObjectIdFromRefField ( records [ index ] [ field ] ) . toString ( ) ] ) { records [ index ] [ 'rendered' ] [ field ] = refColData [ field ] . rendered [ linz . api . model . getObjectIdFromRefField ( records [ index ] [ field ] ) . toString ( ) ] ; } // We're all done here. return fieldDone ( ) ; } // This will only execute if we don't have a ref field. let args = [ ] ; // value is not applicable for virtual field if ( ! req . linz . model . list . fields [ field ] . virtual ) { args . push ( records [ index ] [ field ] ) ; } args . push ( mongooseRecords [ index ] ) ; args . push ( field ) ; args . push ( req . linz . model ) ; args . push ( function ( err , value ) { if ( ! err ) { records [ index ] [ 'rendered' ] [ field ] = value ; } return fieldDone ( err ) ; } ) ; // call the cell renderer and update the content with the result // val, record, fieldname, model, callback req . linz . model . list . fields [ field ] . renderer . apply ( this , args ) ; } , function ( err ) { recordDone ( err ) ; } ) ; } , function ( err ) { cb ( err ) ; } ) ; }
create the values for the datalists for each doc
create the values for the datalists for each doc