Created
October 16, 2011 05:18
-
-
Save logankoester/1290535 to your computer and use it in GitHub Desktop.
Add JSON info to a table using ICanHazJS to render an embedded Mustache template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> | |
<script type="text/javascript" src="https://raw.github.com/andyet/ICanHaz.js/master/ICanHaz.min.js"></script> | |
<script type="text/javascript"> | |
var add_info = function(data){ | |
var parsedData = $.map(data, function(item){ | |
var keys = $.map(item, function(k, v){return({name: v})}); | |
return({'keys': keys}); | |
}); | |
var html = ich.info_table({info: parsedData}); | |
$('#info').append(html); | |
}; | |
/* Let's try it out.. */ | |
$(document).ready(function(){ | |
var data = [ | |
{"fans": 50, "twitter_id": "1", "name": "foo"}, | |
{"fans": 32, "twitter_id": "2", "name": "bar"} | |
]; | |
add_info(data); | |
}); | |
</script> | |
</head> | |
<body> | |
<script id="info_table" type="text/html"> | |
<table border="1"> | |
{{#info}} | |
<tr>{{>info_keys}}</tr> | |
{{/info}} | |
</table> | |
</script> | |
<script id="info_keys" class="partial" type="text/html"> | |
{{#keys}} | |
<td>{{name}}</td> | |
{{/keys}} | |
</script> | |
<div id="info"></div> | |
</body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment