In your initial fiddle you are applying the view model to the entire dom (or more specifically window.document.body
) because you are not supplying a context element. Therefore you do not need the with
binding (the with
binding creates a new binding context whereas you're already in the correct binding context)
See: http://jsfiddle.net/zeEFP/10/
If you wish for multiple view models then you can supply a context to the applyBindings
method:
ko.applyBindings(new FirstViewModel(), document.getElementById("someId));
See the updated fiddle here: http://jsfiddle.net/zeEFP/8/
If you do not like having additional markup to supply as a context for the applyBindings
you can instead use an over-arching view model and then use the with
binding to create new contexts for parts of the page
See: http://jsfiddle.net/zeEFP/11/
Hope that helps clear things up for you