我正在使用Knockout 3.0.0.Js ..但无法在我的机器上运行它。按照我认为代码似乎很好。需要帮忙 。 [英] I Am Using Knockout 3.0.0.Js.. But Unable To Run This On My Machine. As Per I Think Code Seems To B Fine. Need Help .

查看:71
本文介绍了我正在使用Knockout 3.0.0.Js ..但无法在我的机器上运行它。按照我认为代码似乎很好。需要帮忙 。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

This is my javascript:

<script src="../Scripts/knockout-3.0.0.js"></script>
<script type="text/javascript">
    alert("hiii");
        function AppViewModel() {
        this.firstName = ko.observable("Amol");
        this.lastName = ko.observable("Padher");

        this.fullName = ko.computed(function () {
            return this.firstName() + " " + this.lastName();
        }, this);

        this.capitalizeLastName = function () {
            var currentVal = this.lastName(); // Read the current value
            this.lastName(currentVal.toUpperCase()); // Write back a modified value
        };
    }

    // Activates knockout.js
    ko.applyBindings(new AppViewModel());
</script>







Below the html code:

<body>
    <form id="form1" runat="server">
        <div>
        <!-- This is a *view* - HTML markup that defines the appearance of    your UI -->

            <p>First name: <strong data-bind="text: firstName"></strong></p>
            <p>Last name: <strong data-bind="text: lastName"></strong></p>

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

            <p>Full name: <strong data-bind="text: fullName"></strong></p>

            <button data-bind="click: capitalizeLastName">Go caps</button>
        </div>
    </form>
</body>
How to run the above code using Knockout? I.e. how to call the function AppViewmodel() in this program? please sugguest me any solution!!

推荐答案

我得到了解决方案。它是 -

i got the solution. and it is-


(document).ready(function(){
< span class =code-comment> // 激活knockout.js
ko.applyBindings( new AppViewModel());
})
(document).ready(function (){ // Activates knockout.js ko.applyBindings(new AppViewModel()); })


这篇关于我正在使用Knockout 3.0.0.Js ..但无法在我的机器上运行它。按照我认为代码似乎很好。需要帮忙 。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆