zoukankan      html  css  js  c++  java
  • 监控数组与foreach绑定Knockout.js

    html:

    <h2>Your seat reservations</h2>

    <table>
        <thead>

        <tr>
               <th>Passenger name</th>

          <th>Meal</th>

          <th>Surcharge</th>

          <th></th>
          </tr>

      </thead>
        <tbody data-bind="foreach: seats">
            <tr>
                <td data-bind="text: name"></td>
                <td data-bind="text: meal().mealName"></td>
                <td data-bind="text: meal().price"></td>
            </tr>    
        </tbody>
    </table>
    <select data-bind="foreach: seats">
        <option data-bind="text: name;value:text: meal().price"></option>
    </select>

    js代码:

    // 一个构造函数
    function SeatReservation(nameinitialMeal{
        var self this;
        self.name name;
        self.meal ko.observable(initialMeal);
    }

    //数据模型
    function ReservationsViewModel({
        var self this;

        //数据
        self.availableMeals [
            mealName"Standard (sandwich)"price},
            mealName"Premium (lobster)"price34.95 },
            mealName"Ultimate (whole zebra)"price290 }
        ];    

        // 监控数组
        self.seats ko.observableArray([
            new SeatReservation("Steve"self.availableMeals[0]),
            new SeatReservation("Bert"self.availableMeals[1])
        ]);
    }
    //传递数据
    ko.applyBindings(new ReservationsViewModel());

    效果页:

    Your seat reservations

    Passenger nameMealSurcharge 
    Steve Standard (sandwich) 0
    Bert Premium (lobster) 34.95

  • 相关阅读:
    3com1100、3300未知故障升级软件后消失
    俺去测量去了,每天更新图片!!
    windows Installer出错的解决方法
    Gmail的POP3设置
    SharePonit 相关连接收集
    路由器默认密码
    今天dudu说区域很重要,我去读了一下
    CAD画任意角度线的方法
    修改动网新闻.net
    多条语句连续insert into 报ora00911解决方法
  • 原文地址:https://www.cnblogs.com/lbonet/p/6482765.html
Copyright © 2011-2022 走看看