Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2013, 11:00 PM   PM User | #1
nikos101
Senior Coder

 
nikos101's Avatar
 
Join Date: Dec 2006
Location: London
Posts: 1,004
Thanks: 58
Thanked 10 Times in 10 Posts
nikos101 is an unknown quantity at this point
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>
__________________

nikos101 is offline   Reply With Quote
Old 01-29-2013, 01:16 AM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
= @Model.IsFol...
i don't think that's legal
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 01-29-2013, 01:20 AM   PM User | #3
nikos101
Senior Coder

 
nikos101's Avatar
 
Join Date: Dec 2006
Location: London
Posts: 1,004
Thanks: 58
Thanked 10 Times in 10 Posts
nikos101 is an unknown quantity at this point
sorry,false is rendered in that case

no script errors
__________________

nikos101 is offline   Reply With Quote
Old 01-29-2013, 02:03 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,462
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
@ 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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:35 AM.


Advertisement
Log in to turn off these ads.