Joe Lotz
Posts: 0
Joined: Mon Jul 01, 2013 10:00 pm

Dynamically Populating Select List from json data

Hi all,

I'm trying to populate a select list from json data. How do I apply these array values dynamically into list?

My first instinct is to use .getJSON and then iterate over the data and append a select option. But that is not using the Appery API, so I built a service that is invoke on load to retrieve json from https://opendata.socrata.com/resource...
I assigned it variable name $features, then I feel like I need to map it into values of the select item.

Image

I guess I'm lost as to the approach. I thought about assigning the select null values and then changing them on click like the fruit/vegetable tutorial but that didn't really flush out either.

Any thoughts??
Thanks!!!

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Dynamically Populating Select List from json data

Hi,

Try to map "$features" to "mobileselectmenuitem_21".

Joe Lotz
Posts: 0
Joined: Mon Jul 01, 2013 10:00 pm

Dynamically Populating Select List from json data

Hi, I remapped the variable to the menuitem as suggested.
Image

Does the appery interface know to loop through and fill the list or do I need to write javascript? I tried loading service on page load and on list value change but they come out null.

Image

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Dynamically Populating Select List from json data

Check that your service doesn't generate an error message (in console).

Just as a side note, Appery.io is a tool.. it generates JS code that runs in the browser and will loop over items in a collection and print .

Joe Lotz
Posts: 0
Joined: Mon Jul 01, 2013 10:00 pm

Dynamically Populating Select List from json data

very cool. I'm getting there. I figured I'd back track and work my way back up. I decided to try to duplicate one of the tutorials with my data to try.

I switched to xml and using a list versus a select object. btw, no errors in the console.

Here's the data http://opendata.socrata.com/resource/...

Here's my mapping Image

I'm getting results!!! But only the first item :-(
Image

It doesn't seem to either like my data format or I'm still not mapping correctly. Thanks for your help.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Dynamically Populating Select List from json data

Map the "row" above -- that's probably the collection.

Joe Lotz
Posts: 0
Joined: Mon Jul 01, 2013 10:00 pm

Dynamically Populating Select List from json data

Sorry, I did map the collection "row" above to produce the single row. The image attached is incorrect. Do you think it is my data format?
http://opendata.socrata.com/resource/...

Return to “Issues”