Click here to Skip to main content
14,123,619 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 3 Sep 2015
Licenced CPOL

How To Populate a Select Element with Data From a JSON File in a Meteor App

, 3 Sep 2015
Rate this:
Please Sign up or sign in to vote.
Populating Select Elements' Options Values with "lookup" data stored in your settings.json file in your Meteor apps

The No-No SQL Way of populating Select Elements' Options Values

In a previous tip here, I showed how you can insert values into a MongoDB ("No SQL") Collection and then read them out using Meteor's Spacebars template language to populate a Select elements' Options values. This tip is similar but, instead of storing the data in and retrieving it out of a MongoDB Collection, it is stored/retrieved from a .json file. Here are the steps to do that:

First, put some data into a file, perhaps named settings.json, that resides directly beneath your project folder:

{"public" : { "uccampus": [ {"name":"UC Santa Cruz"}, {"name":"UC Berkeley"}, 
{"name":"UC Davis"}, {"name":"UC Irvine"}, {"name":"UC Los Angeles"}, 
{"name":"UC Merced"}, {"name":"UC Riverside"}, {"name":"UC San Diego"}, 
{"name":"UC San Francisco"}, {"name":"UC Santa Barbara"} ] }}

Second, add a helper for the Template in which the Select element resides, like so:

    uccampus: function(){
        return Meteor.settings.public.uccampus;

Third, add this to the HTML for that Select element (instead of things like "<option value="dp">Duckbilled Platypus</option>"):

{{#each uccampus}}

Note: When using this code, and running your Meteor app from its directory in the console, it is not enough to simply enter "meteor run" or "meteor". You need to enter "meteor --settings settings.json" (where "settings.json" is the name of the file containing the json data); and the said json file must reside directly beneath your project's folder - not in a subfolder.

Don't Neglect the Superhero's Superhero (After Meteor Man, of course)

If you like this tip, tip your hat to Top Cat the next time that you see him. If you have no hat, tip your toupée; if you don't wear a toupée, tou·ché Turtle soup of the day Trip the Light Fantastic Four Horsemen of the Apocalypse sinks ships ahoy, Matey s. Eliott Gould.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

B. Clay Shannon
Founder Across Time & Space
United States United States
I am in the process of morphing from a software developer into a portrayer of Mark Twain. My monologue (or one-man play, entitled "The Adventures of Mark Twain: As Told By Himself" and set in 1896) features Twain giving an overview of his life up till then. The performance includes the relating of interesting experiences and humorous anecdotes from Twain's boyhood and youth, his time as a riverboat pilot, his wild and woolly adventures in the Territory of Nevada and California, and experiences as a writer and world traveler, including recollections of meetings with many of the famous and powerful of the 19th century - royalty, business magnates, fellow authors, as well as intimate glimpses into his home life (his parents, siblings, wife, and children).

Peripatetic and picaresque, I have lived in eight states; specifically, besides my native California (where I was born and where I now again reside) in chronological order: New York, Montana, Alaska, Oklahoma, Wisconsin, Idaho, and Missouri.

I am also a writer of both fiction (for which I use a nom de plume, "Blackbird Crow Raven", as a nod to my Native American heritage - I am "½ Cowboy, ½ Indian") and nonfiction, including a two-volume social and cultural history of the U.S. which covers important events from 1620-2006:

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
PVX0078-Sep-15 5:39
memberPVX0078-Sep-15 5:39 
GeneralRe: My vote of 5 Pin
B. Clay Shannon8-Sep-15 5:46
professionalB. Clay Shannon8-Sep-15 5:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190518.1 | Last Updated 3 Sep 2015
Article Copyright 2015 by B. Clay Shannon
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid