CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   ko.computed does not update (http://www.codingforums.com/showthread.php?t=286878)

nikos101 02-01-2013 03:50 PM

ko.computed does not update
 
How come the followButtonText doesn't update then isFollowing is changed?
Code:

    function AppViewModel() {

                this.toggleIsFollowing = function () {
                    this.isFollowing = !this.isFollowing
                };

                this.isFollowing = ko.observable(false);
                this.followButtonText = ko.computed(function () {
                    return this.isFollowing ? "Unfollow" : "Follow";
                });
            }

            ko.applyBindings(new AppViewModel());


Dormilich 02-02-2013 11:43 AM

there is not enough information (esp. about the ko instance) to say anything definite. it might be a scope issue, it might be that the methods do not do what you expect …

nikos101 02-02-2013 12:49 PM

this is all the code for KO in this app

Code:

<script type="text/javascript">
        $(document).ready(function () {


            function AppViewModel() {

                this.toggleIsFollowing = function () {
                    this.isFollowing = !this.isFollowing;
                    follow();
                };

                this.isFollowing = ko.observable(false);
                this.followButtonText = ko.computed(function () {
                    return this.isFollowing ? "Unfollow" : "Follow";
                });
            }

            ko.applyBindings(new AppViewModel());

        });
    </script>

and HTML element using that text:

Code:

<button class="radius secondary button" data-bind="text: followButtonText,click: toggleIsFollowing"></button>

Dormilich 02-02-2013 12:54 PM

Quote:

Code:

this.isFollowing = ko.observable(@Model.IsFollowing.ToString().ToLower());

which language is that? and what part thereof is JS?

if the posted code is everything and ko is supposedly a JS object, you will get a TypeError (ko is null or not an object).

nikos101 02-02-2013 12:55 PM

sorry that gets compiled to false serverside, its Razor asp mvc syntax

Dormilich 02-02-2013 12:58 PM

well, the question about the ko variable remains.

nikos101 02-02-2013 01:30 PM

sorry I don't get what you mean by ko var.

I just use it like this site:
http://learn.knockoutjs.com/#/?tutorial=intro

Dormilich 02-02-2013 01:37 PM

aah, now it makes way more sense.

nikos101 02-02-2013 01:53 PM

1000sandth post!"!!!!!! :)


All times are GMT +1. The time now is 08:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.