Skip to content

Instantly share code, notes, and snippets.

@potato4d
Created January 18, 2016 02:15
Show Gist options
  • Save potato4d/3d238be700350be64f8e to your computer and use it in GitHub Desktop.
Save potato4d/3d238be700350be64f8e to your computer and use it in GitHub Desktop.
underscore.jsの機能使ってごにょごにょ。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>underscore.js sample</title>
</head>
<body>
<ul id="list">
</ul>
<script type="text/template" id="test-template">
<li>
No.<%- index %>: <b><%- content %></b>
</li>
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script>
$(function (){
var _testTemplate = _.template($("#test-template").text());
var list = [
100,
10,
20,
50,
90
];
(function (){
var index = 1;
_.chain(list)
.shuffle()
.each(function (number){
var data = {
content: number,
index: index
};
$("#list").append(_testTemplate(data));
index++;
});
}());
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment