I made a fiddle to illustrate the issue:
Update: Here's an updated fiddle:
When used with Knockout 2.0.0, your fiddle will work: http://jsfiddle.net/mbest/RRVrQ/4/.
The difference when using the latest Knockout is that I'm using the new ko.bindingContext.extend function, which creates a child context (but with $data == $parent). This wasn't how I thought it should work, but see issue 290 where Steve and I discussed this topic in depth. To make your code work with the new version, change $parent to $parents: http://jsfiddle.net/mbest/RRVrQ/5/
$data == $parent
So, the first parent is the case binding and the second is the switch binding? I wonder if Steve would reconsider that extensibility point, seeing how it affects consistency in this multi-stage binding. If not, it might help others to have a note about this in the documentation.
No, case doesn't create a child context; only switch does. There are two parents because with also creates a child context:
$data = $root = vm
$data = vm.sub
$parents = $parent = $root = vm
$data = $parent = $parents = vm.sub
$parents = $root = vm
I still think it's confusing to have the extra "parent" and I wonder if it might be better to consider that a child context that doesn't change the value of $data should also not change $parent or $parents.
I submitted a pull request for Knockout to change bindingContext.extend to keep $parent the same.
Okay, now I understand your first comment better. I think this counts as a real world use case where we would benefit from that change, so maybe Steve will change his mind. Thank you for the explanation.
For anyone reading here from the pull request, I modified the fiddle to be easier to follow, and added this fiddle to the original post.
The latest Knockout code has been changed so that bindingContext.extend works the way it should. We'll have to wait for Steve to re-build it before we can see it working though.
That's good news. I'm looking forward to testing the next build.
Okay the build is updated. I tested your fiddle and had to take out the $parents.name bindings: http://jsfiddle.net/RRVrQ/9/
Looks good to me. Thanks!