侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

knockoutjs hello world

2024-05-13 星期一 / 0 评论 / 0 点赞 / 93 阅读 / 2088 字

<p>First name: <input data-bind="value: firstName" /></p> <p>Last name: <input data-bind="value: las

 

<p>First name: <input data-bind="value: firstName" /></p>

<p>Last name: <input data-bind="value: lastName" /></p>

<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>

// Here's my data model

var ViewModel = function(first, last) {

    this.firstName = ko.observable(first);

    this.lastName = ko.observable(last);

 

    this.fullName = ko.pureComputed(function() {

        // Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.

        return this.firstName() + " " + this.lastName();

    }, this);

};

 

ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes Knockout get

广告 广告

评论区