Skip to content

Instantly share code, notes, and snippets.

@ducin
Last active December 5, 2016 17:08
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 ducin/0c8b531b226bdecaa5f72d23587fc014 to your computer and use it in GitHub Desktop.
Save ducin/0c8b531b226bdecaa5f72d23587fc014 to your computer and use it in GitHub Desktop.
node_modules
function bookTemplate(book) {
return '<strong>' + book.author + '</strong>: ' + book.id;
}
function booksTemplate(books) {
var html = books.map(function(book){
return '<li>' + bookTemplate(book) + '</li>';
}).join('')
return '<ul>' + html + '</ul>';
}
$(document).ready(function () {
// var x = 0;
$('#btn').on('click', function () {
// x += 1;
// console.log('siema!');
// $('#container').html('olaboga' + x);
$.get('http://localhost:3000/books').then(function(response){
// console.log(response);
// console.log(booksTemplate(response));
$('#container').html(booksTemplate(response));
});
});
});
<html>
<head>
<title>Buka</title>
<script src="node_modules/jquery/dist/jquery.js"></script>
<script src="node_modules/handlebars/dist/handlebars.js"></script>
<script src="app.js"></script>
</head>
<body>
<h1>Hello, my friend!</h1>
<button id='btn'>Click me!</button>
<div id='container'></div>
</body>
</html>
{
"name": "anxi-git",
"version": "1.0.0",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"dependencies": {
"handlebars": "^4.0.6",
"jquery": "^3.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment