zoukankan      html  css  js  c++  java
  • knockout.js 练习一

    knockout.js主要是为了解决UI层与数据层绑定而产生的,这件主要学习knockout 中的observable(监控性)以及computed(依赖监控):

    例如现在我要给一个firstName,lastName绑定数据,那么我可以直接这样写:先写下html

    <!DOCTYPE html>
    <html>
      <head>
        <title>observable、 computed</title>
    </head>
    <body>
       <label>firstName</label><input data-bind="value:firstName"    type="text" />
      <label>lastName</label><input data-bind="value:lastName"  type="text"/>
       <label>fullName<label><input data-bind="value:fullName"  type="text">
    </body>
    </html>
    

      

    <script type="text/javascript">
       var viewModel = function(first,last){
    
         var self = this;
         self.firstName = ko.observable(first);
         self.lastName = ko.observable(last);
        self.fullName = ko.computed(function(){
            return this.firstName +"" + this.lastName;
        },this);
      };
    </script>
    只要肯努力学习工作,面包会有的,牛奶也会有的
  • 相关阅读:
    nyist 541最强DE 战斗力
    nyist 231 Apple Tree
    nyist 543 遥 控 器
    nyist 233 Sort it
    nyist 517 最小公倍数
    hdu 1sting
    nyist A+B Problem IV
    nyist 522 Interval
    nyist 117 求逆序数
    nyist 600 花儿朵朵
  • 原文地址:https://www.cnblogs.com/sandraMaying/p/ko_obervable.html
Copyright © 2011-2022 走看看