Sunday, November 8, 2015

View 2

<!DOCTYPE html>
<html>
<head>
<title>Backbone.js Todo App</title>
<script src="jquery.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>

</head>
<body>
<div > <img src="run.gif" height="100px"></div>

<div id="container"> <img src="run.gif"></div>

<script id="task_template" type="text/template">
<label> Todo </label>
<input id="task_desc" type="text"/>
<button> Add Task </button>
</script>

<script type="text/javascript">
Todo = Backbone.View.extend({
el: $('#container'),

initialize: function(){
this.render();
},

render: function(){
var template= _.template($('#task_template').html());
this.$el.html(template);

},

events:{
'click button' : 'fn_click'
},
fn_click: function(){
alert($('#task_desc').val());
}

});

var todo = new Todo();
</script>


</body>
</html>

View1

<!DOCTYPE html>
<html>
<head>
<title>Backbone.js Todo App</title>
<script src="jquery.js"></script>
<script src="underscore.js"></script>
<script src="backbone.js"></script>

</head>
<body>


<div id="wrapper">crea...</div>

<script type="text/javascript">
Task = Backbone.View.extend({
el: $('#wrapper'),

template: _.template('<h1>Hello <%= who %></h1>'),

initialize: function(){
this.render();
},

render:function(){
this.$el.html(this.template({who:'Haloom'}));
}
});

var task = new Task();
</script>

</body>
</html>