Knockout Lists
How do I make an knockout lists?
What is a knockout lists? How do you make a knockout lists? This script and codes were developed by Ruslan Marin on 07 December 2022, Wednesday.
Knockout Lists - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Knockout Lists</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h2>Заказы (<span data-bind="text: seats().length"></span>)</h2>
<table> <thead> <tr> <th>Client name</th> <th>Meal</th> <th>Surcharge</th><th></th> </tr> </thead> <tbody data-bind="foreach: seats"> <tr> <td> <input data-bind="value: clientName" /> </td> <td class="centered"> <select data-bind="options: $root.menu, value: meal, optionsText: 'name'"></select> </td> <td data-bind="text: meal().formattedPrice" class="centered"></td> <td><a href="#" data-bind="click: $root.removeSeat, text: 'Remove'"></a></td> </tr> </tbody>
</table>
<button data-bind="click: addSeat, enable: seats().length < 5">Reserve another seat</button>
<h3 data-bind="visible: total() > 0"> Итого: <span data-bind="text: '$' + total().toFixed(2)"></span>
</h3> <script src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.0/knockout-min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Knockout Lists - Script Codes CSS Codes
table { background-color: lightgreen;
}
.centered { text-align: center;
}
Knockout Lists - Script Codes JS Codes
// Конструктор блюда
function Meal(name, price) { var self = this; self.name = name; self.price = price; self.formattedPrice = ko.computed(function(){ return self.price ? "$" + self.price.toFixed(2) : "-"; });
}
// Конструктор заказа
function SeatReservation(name, initialMeal) { var self = this; self.clientName = name; self.meal = ko.observable(initialMeal);
}
// viewmodel с информацией о заказах
function ReservationsViewModel() { var self = this; // Меню self.menu = [ new Meal("Standard (sandwich)", 0 ), new Meal("Premium (lobster)", 34.95 ), new Meal("Ultimate (whole zebra)", 290 ), ]; // Начальные заказы self.seats = ko.observableArray([ new SeatReservation("Lisa", self.menu[0]), new SeatReservation("Bart", self.menu[1]), new SeatReservation("Homer", self.menu[2]) ]); self.addSeat = function() { self.seats.push(new SeatReservation("", self.menu[0])); }; self.removeSeat = function(seat) { self.seats.remove(seat); }; self.total = ko.computed(function(){ var total = 0; for (var i = 0; i < self.seats().length; i++) { total += self.seats()[i].meal().price; } return total; });
}
ko.applyBindings(new ReservationsViewModel());

Developer | Ruslan Marin |
Username | marinru |
Uploaded | December 07, 2022 |
Rating | 3 |
Size | 2,531 Kb |
Views | 4,046 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Rotating Cube with p5.js | 2,148 Kb |
Vue.js Conditional Visibility | 1,520 Kb |
SimplePager | 4,584 Kb |
Vue 001. Hello World | 1,438 Kb |
Socket.io Client Demo | 1,490 Kb |
KO Components Demo | 2,994 Kb |
Rotating Cubes with p5.js | 1,753 Kb |
Simple Component Example 2 | 2,099 Kb |
Component Props | 3,113 Kb |
Sidescroller with p5.js | 2,455 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Hoi hoi | JohnTheCat | 7,248 Kb |
Flat iOS 7 Safari Icon | Rss | 3,332 Kb |
Hovers with popups | Zacharyolson | 2,380 Kb |
CSS3 iPad | Vikvarg | 1,766 Kb |
Octopus Bar iPad App Interactions | Davidkpiano | 6,735 Kb |
SlideupBoxes | Gavra | 23,772 Kb |
Google Chrome Icon using Pure CSS in one DIV | Grssam | 3,627 Kb |
A Pen by Oliver Schafeld | Schafeld | 1,720 Kb |
A Pen by Final Boss tommyb9 | FBtommyb9 | 55,354 Kb |
Atom | Bhlaird | 1,932 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!