Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,007
    Thanks
    59
    Thanked 10 Times in 10 Posts

    Question 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>


  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    = @Model.IsFol...
    i don't think that's legal
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #3
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,007
    Thanks
    59
    Thanked 10 Times in 10 Posts
    sorry,false is rendered in that case

    no script errors


  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,374
    Thanks
    11
    Thanked 592 Times in 572 Posts
    @ 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";
            });
        }
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •