Data object from mongo collection?

I’ve been trying to figure out how to do this for a couple of days, and so far I’m not coming up with much.

I’m using Materialize css, and want to use the chips to display selections made in a field. The chips in Materialze have the ability to use auto-text if you provide a data object in the javascript.

I want to pull colors and their color code from a collection, and use that as the data object for the auto-text options.

The data object looks like

data:
    {
        key: value,
        key: value, 
        ...
    }

My collection of colors is setup like this:

{
	"_id" : "AKy6jw5R7fXMxAbzd",
	"veh_color_code" : "MAR",
	"veh_color_desc" : "Maroon",
	"active" : true
}
{
	"_id" : "udYzmi2vz3KHEGSzp",
	"veh_color_code" : "PUR",
	"veh_color_desc" : "Purple",
	"active" : true
}

I’m tryingn to get the veh_color_code and veh_color_desc into the key:value setup of the data object and fill it when the user moves to that page.

I’m just not being successful at it so far. Could really use some help on this.

As a reference, here’s the info from Materialize site on using autocompletion in chips:

$('.chips-autocomplete').material_chip({
    autocompleteOptions: {
      data: {
        'Apple': null,
        'Microsoft': null,
        'Google': null
      },
      limit: Infinity,
      minLength: 1
    }
  });

As you can see, the data object is not an array, or separate objects, but one object with multiple key: value pairs.

If I understand the question, you want to map the contents of the collection documents to an object with key:value pairs.

You can probably use lodash _.keyBy function. If you want to avoid this you can do something like:

const colors = ColorsCollection.find().fetch();
let dataObject = {};
_.each(colors, (color)=>{
    dataObject[veh_color_code] = veh_color_desc;
});

and then,

$('.chips-autocomplete').material_chip({
    autocompleteOptions: {
      data: dataObject,
      limit: Infinity,
      minLength: 1
    }
  });

I hope this is helpful (and answers the right question)

You absolutely do understand correctly. I appreciate the guidance. I’ll give this a shot and see how it goes.