下面是來自Knockout.js教程網站採取代碼:反思Knockout.js教程
function SeatReservation(name, initialMeal) {
var self = this;
self.name = name;
self.meal = ko.observable(initialMeal);
}
//View Model along with initialState
function ReservationsViewModel() {
var self = this;
//Non-edible data
self.availableMeals = [
{mealName:"sandwhich", price: 0 },
{mealName: "Ribs", price:25 },
{mealName: "Steak", price: 50}
];
//Edible data
self.seats = ko.observableArray([
new SeatReservation("Steve", self.availableMeals[0]),
new SeatReservation("Bert", self.availableMeals[0])
ko.applybindings(new ReservationsViewModel()):
的觀點:
<tbody data-bind="foreach: seats">
<td data-bind = "text:name"></td>
<td data-bind = "text: meal().mealName"></td>
<td data-bind = "text: meal().price"></td>
我不明白的是爲什麼認爲是調用膳食()。膳食和膳食()。價格。 ()。availableMeals.mealName and meal()。availableMeals.price
現在我可以休息今晚。謝謝 – user2202911