CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   KnockoutJS things like binding don't work (http://www.codingforums.com/showthread.php?t=286602)

nikos101 01-28-2013 11:00 PM

KnockoutJS things like binding don't work
 
What do you do when simple
KnockoutJS 2.0 things like this don't work(button text is empty), and the sources load properly

Code:

<script type="text/javascript">



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

        this.isFollowing = @Model.IsFollowing.ToString().ToLower()
        this.followButtonText = ko.computed(function () {
            return this.isFollowing ? "Follow" : "Unfollow";
        });
    }

    ko.applyBindings(new AppViewModel());

</script>

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


rnd me 01-29-2013 01:16 AM

Quote:

= @Model.IsFol...
i don't think that's legal

nikos101 01-29-2013 01:20 AM

sorry,false is rendered in that case

no script errors

rnd me 01-29-2013 02:03 AM

@ is a syntax error...

well, you also re-define the function toggleIsFollowing() as false, probably not what you want to do.


if that's not it, it sound like the this/that thing we usually see in dom events.
why not just close it instead of going through knockout?


Code:

function AppViewModel() {
      var toggled = true;
        this.toggleIsFollowing = function () {
          toggled  = !toggled
        };

        this.isFollowing = @Model.IsFollowing.ToString().ToLower()
        this.followButtonText = ko.computed(function () {
            return toggled  ? "Follow" : "Unfollow";
        });
    }



All times are GMT +1. The time now is 10:26 AM.

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