JSFiddle - React, Tailwind, and code Playground

by 3gwebtrain

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<div class="container">
		<h1>Student Manager</h1>
		<hr>
		<div class="page">
			<a id="highScoreBtn" class="btn btn-primary" href="#">Show high Score</a>
			<hr>
			<ul>
				
			</ul>
		</div>
	</div>
	<script id="studentTemplate" type="text/template">
		<strong>Name :</strong> <%= name %> <span>Scored:</span> <%= scored %>
	</script>

CSS

li{
			border-bottom:1px solid gray;
			list-style: none;
			padding: 10px;
		}
		ul{
			padding:0;
			margin:0;
		}

		li:last-child{
			border: 0;
		}

JavaScript

var student = [
		{name:"student0",scored:75},{name:"student1",scored:49},{name:"student2",scored:25},
		{name:"student3",scored:96},	{name:"student4",scored:42},	{name:"student5",scored:85},	
		{name:"student6",scored:68},	{name:"student7",scored:19},	{name:"student8",scored:85},
		{name:"student9",scored:26}
	]


var model = Backbone.Model.extend({
    defaults:{
        name:"undefined",
        scored:"0"
    }
});

var collection = Backbone.Collection.extend({
    model:model
});

var studentView = Backbone.View.extend({
	tagName:'li',
	className:"list",
	events:{
		'click .list':"called"
	},
	template:_.template($("#studentTemplate").html()),
	render:function(){
		this.$el.append(this.template(this.model.toJSON()));
		return this;
	},
	called:function(){
		alert("i a called")
	}
});

var studentsView = Backbone.View.extend({
    el:$(".page"),
    events:{
    	"click #highScoreBtn":"showHighScore"
    },
    initialize:function(){
    	this.collection = new collection(student);
    	this.render();
    },
    render:function(){
    	var that = this;
        _.each(this.collection.models, function(item){
        	that.$el.find('ul').append(new studentView({model:item}).render().el);
        })
    }
})

var newStudentList = new studentsView();