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({ | |
promptName: function() { | |
var name = prompt("Please enter your name:"); | |
this.set({name: name}); | |
} | |
}); |
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
window.person = new Person; | |
var myCallback = function(personModel, enteredName) { | |
alert(‘Hello’ + enteredName); | |
}; | |
person.bind('change:name', myCallback); | |
person.promptName(); |
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
window.person = new Person; | |
var myCallback = function(personModel, enteredName) { | |
alert(‘Hello’ + enteredName); | |
}; | |
person.bind('change:name', myCallback); | |
person.promptName(); |
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 PersonModel = Backbone.Model.extend(); | |
var PersonView = Backbone.View.extend({ | |
initialize: function () { | |
_.bind(this, 'render’); | |
this.model.bind(‘change:name’, this.render); | |
}, | |
render: function () { | |
$(‘body’).html(this.model.get(‘name’)); | |
} | |
}); |
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 persons = new Backbone.Collection(); | |
persons.bind("add", function(person) { | |
alert("Servus " + person.get("name") + "!"); | |
}); | |
persons.add([ | |
{name: "Marcus"}, | |
{name: "Maria"}, | |
]); |
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 myRouter = Backbone.Router.extend({ | |
routes: { | |
"gallery/:image": "gallery" | |
}, | |
gallery: function(image) { | |
// do something nice | |
} | |
}); |
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> | |
<script src="jquery-1.7.1.min.js"></script> | |
<script src="jquery.tmpl.js"></script> | |
<script src="http://ajax.cdnjs.com/ajax/libs/underscore.js/1.1.6/underscore-min.js"></script> | |
<script src="backbone.js"></script> | |
</head> | |
<body> | |
You have <span class="js-wish-counter">0</span> wishes. |
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
<!-- VIEW --> | |
My name is <b data-bind=”text: personName“></span> | |
// VIEW-MODEL | |
var viewModel = { | |
personName: ’Marco Francke’ | |
}; | |
// ACTIVATE KNOCKOUT | |
ko.applyBindings(viewModel); |
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
My name is <b>Marco Francke</b> |
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 viewModel = { | |
personName: ko.obervable(’Marco Francke’) | |
}; |
OlderNewer