Last active
December 15, 2015 15:29
-
-
Save ducin/5282481 to your computer and use it in GitHub Desktop.
ICanHaz loop demo: example showing how to render looped data
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
$(document).ready( function() { | |
$('#display').click(function () { | |
var data = [ | |
{ | |
"name": "Paul McCartney", | |
"email": "[email protected]", | |
"salary": "400" | |
}, | |
{ | |
"name": "John Lennon", | |
"email": "[email protected]", | |
"salary": "450" | |
}, | |
{ | |
"name": "George Harrison", | |
"email": "[email protected]", | |
"salary": "400" | |
}, | |
{ | |
"name": "Ringo Starr", | |
"email": "[email protected]", | |
"salary": "300" | |
} | |
]; | |
var table = ich.displayTable({ | |
"users": data | |
}); | |
$('#container').append(table); | |
}); | |
}); |
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/tr/html4/transitional.dtd"> | |
<html> | |
<head> | |
<title>ICanHaz.js loop demo</title> | |
<meta http-equiv="content-type" content="text/html; charset=utf-8"> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/ICanHaz.js/0.10/ICanHaz.min.js"></script> | |
<script type="text/javascript" src="ich-loop.js"></script> | |
<script id="displayTable" type="text/html"> | |
<table border="1"> | |
<thead> | |
<tr> | |
<td>Name</td> | |
<td>Email</td> | |
<td>Salary</td> | |
</tr> | |
</thead> | |
<tbody> | |
{{#users}} | |
<tr> | |
<td>{{ name }}</td> | |
<td>{{ email }}</td> | |
<td>{{ salary }}</td> | |
</tr> | |
{{/users}} | |
</tbody> | |
</table> | |
</script> | |
</head> | |
<body> | |
<p> | |
ICanHaz will render each table row using mustache loop notation. | |
</p> | |
<button id="display">click to add message</button> | |
<div id="container"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment