I’ve got a mass of values in a JSON file containing the names of venues and their contact information along with a description. I’d like to generate a table listing the contents of the JSON file on my page. I’m hoping to create a live search function that removes each entry that is no longer relevant with eachkeyUpdetected.
The JSON
[
{
"name": "Aquarium Café Bar",
"site": "http://www.aquariumcafebar.ca",
"address": "2923 Masson 728-6116",
"genre": "default"
},
{
"name": "Aréna Pierre “Pete” Morin",
"site": "none",
"address": "1925 St-Antoine 634-3471",
"genre": "default",
}
]
The Proposed HTML
<table>
<thead>
<tr>
<th>Venue</th>
<th>Address</th>
<th>Website</th>
<th>Genre</th>
</tr>
</thead>
<tbody>
<tr>
<td>Aquarium Café Bar</td>
<td>2923 Masson 728-6116</td>
<td>http://www.aquariumcafebar.ca</td>
<td>Rock</td>
</tr>
</tbody>
</table>
I’ve got a vague idea of how to grab the JSON from the venues.json file in jQuery, but I would really not know what to do with it once I have it to .append() a containing all the info. I’m just looking for a bit of help with the syntax here!
Oh, and if you happen to have any bright ideas about how to update the table as the user searches, it’d be greatly appreciated!
Love,
BenjiBee
You could use jQuery.tmpl to create a table from the JSON data, using a template like this:
And this jQuery to render the template and inject it into a placeholder/container div named
Container:Then use the quickSearch plugin to interactively filter that data. It can be applied to the table (after rendering, of course) like this: