Skip to content

Instantly share code, notes, and snippets.

@duanemoody
Forked from ducin/ich-loop.js
Last active December 27, 2015 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duanemoody/7358179 to your computer and use it in GitHub Desktop.
Save duanemoody/7358179 to your computer and use it in GitHub Desktop.
$(document).ready( function() {
$('#display').click(function () {
var data = [
{
"name": "Paul McCartney",
"email": "paul.mccartney@beatles.com",
"salary": "400"
},
{
"name": "John Lennon",
"email": "john.lennon@beatles.com",
"salary": "450"
},
{
"name": "George Harrison",
"email": "george.harrison@beatles.com",
"salary": "400"
},
{
"name": "Ringo Starr",
"email": "ringo.starr@beatles.com",
"salary": "300"
}
];
var table = ich.displayTable({
"users": data
});
$('#container').append(table);
});
});
<!doctype html>
<html>
<head>
<title>ICanHaz.js loop demo</title>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/ICanHaz.js/0.10/ICanHaz.min.js"></script>
<script 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>
@duanemoody
Copy link
Author

HTML converted to HTML5 to ensure validation.

  1. Original DOCTYPE incorrectly crafted (the System identifier "http://www.w3.org/tr/html4/transitional.dtd" declares Transitional but PUBLIC "-//W3C//DTD HTML 4.01//EN" is exclusive to 4.01 Strict).
  2. Template scripts cannot pass validation without CDATA wrappers outside HTML5; however, icanhaz.js doesn't strip CDATA wrappers so the templated code is tagless text.
  3. The overall script framework requires an ID attribute on the template script (which is only allowable in HTML5).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment