jQuery(document).ready(function($) {
var FirstModel = Backbone.Model.extend({
initialize: function() {
console.log('Hello, i am here');
}
});
fmodel = new FirstModel();
fmodel.set({
name: "Tuong",
author: "Lionel Pham"
});
var ModelView = Backbone.View.extend({
template: _.template($('#ourTemplate').html()),
el: '#div1',
model: fmodel,
initialize: function() {
this.render();
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
}
});
vmodel = new ModelView();
});
<!DOCTYPE html>
<html>
<head>
<title>Backbone Example</title>
<link rel="stylesheet" href="lib\css\todos.css" />
<script src="lib/js/jquery-1.9.1.js"></script>
<script src="lib/js/underscore.js"></script>
<script src="lib/js/backbone.js"></script>
<script src="app.js"></script>
<script type="text/template" id="ourTemplate">
<%= name %> and Author <%= author %>
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>