Created
April 8, 2013 12:52
-
-
Save ceth-x86/5336581 to your computer and use it in GitHub Desktop.
Backbone : simple view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Person = Backbone.Model.extend({ | |
defaults: { | |
name: 'Nikola', | |
age: 40, | |
job: 'developer' | |
}, | |
work: function() { | |
return this.get('name') + ' is working.'; | |
} | |
}); | |
var PersonView = Backbone.View.extend({ | |
el: $('body'), | |
tagName: 'div', | |
initialize: function() { | |
this.render(); | |
}, | |
render: function() { | |
$(this.el).append(this.model.get('name')); | |
} | |
}); | |
var person = new Person; | |
var personView = new PersonView({model: person}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>backbone.js</title> | |
</head> | |
<body> | |
<script type="text/javascript" src="jquery.js"></script> | |
<script type="text/javascript" src="underscore.js"></script> | |
<script type="text/javascript" src="backbone.js"></script> | |
<script type="text/javascript" src="module.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment