Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 16, 2014 21:44
Show Gist options
  • Save devdays/72506fb3659802291d45 to your computer and use it in GitHub Desktop.
Save devdays/72506fb3659802291d45 to your computer and use it in GitHub Desktop.
Object JavaScript - Mustache + jQuery
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="main-content">
<h1>All Products</h1>
<div id="sampleArea"></div>
</div>
<script id="productTmpl" type="text/template">
Products:
<ul>
{{#products}}
<li>{{name}} {{category}} {{price}}</li>
{{/products}}
</ul>
</script>
<script src="Scripts/jquery-2.0.2.min.js"></script>
<script src="Scripts/mustache.js"></script>
<script>
var data = {};
data.products = {};
$.getJSON(
"Data/products.txt",
function (d) {
data = d;
var template = $("#productTmpl").html();
var html = Mustache.to_html(template, data);
$('#sampleArea').html(html);
}
);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment