Skip to content

Instantly share code, notes, and snippets.

@kappa7194
Created January 17, 2012 13:13
Show Gist options
  • Save kappa7194/1626583 to your computer and use it in GitHub Desktop.
Save kappa7194/1626583 to your computer and use it in GitHub Desktop.
Firefox crash
<!DOCTYPE html>
<html>
<head>
<title>Knockout</title>
<script src="jquery-1.7.1.js"></script>
<script src="knockout-2.0.0.js"></script>
<script>
function SeatReservation(name, meal) {
var self = this;
self.name = ko.observable(name);
self.meal = ko.observable(meal);
}
function ReservationsViewModel() {
var self = this;
self.availableMeals = [
{ type: 'Standard', price: 0 },
{ type: 'Premium', price: 5 },
{ type: 'Deluxe', price: 25 }
];
self.reservations = ko.observableArray([
new SeatReservation('Bob', self.availableMeals[0]),
new SeatReservation('Paul', self.availableMeals[0])
]);
self.addSeat = function () {
self.reservations.push(new SeatReservation('', self.availableMeals[0]));
}
}
$(document).ready(function () {
ko.applyBindings(new ReservationsViewModel());
});
</script>
</head>
<body>
<h1>Knockout</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Meal</th>
<th>Price</th>
</tr>
</thead>
<tbody data-bind="foreach: reservations()">
<tr>
<td data-bind="text: name()"></td>
<td data-bind="text: meal().type"></td>
<td data-bind="text: meal().price"></td>
</tr>
</tbody>
</table>
<p><input data-bind="click: addSeat()" type="button" value="Add a reservation" /></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment