previous and next buttons

59 views
Skip to first unread message

Yannick Smits

unread,
Jan 30, 2012, 1:42:37 PM1/30/12
to KnockoutJS
I can't seem to get a simple previous / next scenario to work. Must be
a simple thing but I'm cracking my head already.
Would appreciate if somebody could have a look:
http://jsfiddle.net/tube8/4/

thanks,
Yannick

Christoffer

unread,
Jan 30, 2012, 2:01:09 PM1/30/12
to KnockoutJS
Have you looked at rpn's fiddle?

http://jsfiddle.net/rniemeyer/FyuSD/

Yannick Smits

unread,
Jan 30, 2012, 4:23:36 PM1/30/12
to KnockoutJS
wonderful! got it working now thanks to this great example.
Here is the working snip: http://jsfiddle.net/tube8/5/

How did you find it? Is there an index of all these great examples
written by Ryan?

Yannick Smits

unread,
Jan 30, 2012, 8:17:48 PM1/30/12
to KnockoutJS
did a little modification to Ryan's sample to test subscriptions, but
for some reason I can't subscribe to the change event of the Step.name
object.
Isn't knockout able to figure out a property inside an observableArray
is changed or is something else happening.

Here is the modified code that doesn't fire the alert upon change of
the header:
http://jsfiddle.net/FyuSD/11/

rpn

unread,
Jan 31, 2012, 12:30:51 AM1/31/12
to knock...@googlegroups.com
Hello-
You have a small typo in your alert.  This:

        alert("kenteken changed to " newvalue);

Should be:

        alert("kenteken changed to " newValue);


You should be good to go after that.

Yannick Smits

unread,
Jan 31, 2012, 6:47:39 AM1/31/12
to KnockoutJS
wow, how did you find that typo?! stared at it for 3 hours...

next step is to track changes of one of the model object members. How
would I do that? I've tried:

self.messageChanged = ko.dependentObservable(function() {
return self.model()["message"];
});

// below line doesn't fire
self.messageChanged.subscribe(function(newValue) {
alert("message changed to " + newValue);
});

without success.
here is the jsfiddle: http://jsfiddle.net/FyuSD/14/

rpn

unread,
Jan 31, 2012, 9:01:34 AM1/31/12
to knock...@googlegroups.com
Your message properties would need to be observable to be notified for that change like:  http://jsfiddle.net/rniemeyer/FyuSD/15/

In your case you have a model observable and it contains an object.  Changes to properties inside that object would not trigger notifications unless you update the entire object.
Reply all
Reply to author
Forward
0 new messages