嵌套这是指向错误的变量

Hel*_*rld 0 javascript knockout.js

在下面的课程中

thisnew SeatReservation("Steve", this.availableMeals[0]),被闯民宅内seats,我如何使它指向正确的一个availableMeals

我可以去吗 new SeatReservation("Steve", parent.this.availableMeals[0]),

// Overall viewmodel for this screen, along with initial state
function ReservationsViewModel() {
    //var self = this;

    // Non-editable catalog data - would come from the server
    this.availableMeals = [
        { mealName: "Standard (sandwich)", price: 0 },
        { mealName: "Premium (lobster)", price: 34.95 },
        { mealName: "Ultimate (whole zebra)", price: 290 }
    ];    

    // Editable data
    this.seats = ko.observableArray([
        new SeatReservation("Steve", this.availableMeals[0]),
        new SeatReservation("Bert", this.availableMeals[0])
    ]);

    // Operations
    this.addSeat = function() {
        self.seats.push(new SeatReservation("", this.availableMeals[0]));
    }
}
Run Code Online (Sandbox Code Playgroud)

epa*_*llo 5

使用self您注释掉的变量

self.availableMeals[0]
Run Code Online (Sandbox Code Playgroud)