A few thoughts:
If you don't want to worry about this dependent, then you can put your statement directly in text binding, for example:
<div data-bind="text: selectedAccount() ? selectedAccount().DocumentList().length : null"></div>
or even shorter:
<div data-bind="text: selectedAccount() && selectedAccount().DocumentList().length"></div>
Depending on your scenario, you can also use template binding to your advantages when dealing with potentially null values. It will be like this:
<div data-bind="template: { name: 'accountTmpl', data: selectedAccount }"></div> <script id="accountTmpl" type="text/html"> ${DocumentList().length} </script>
In addition, in version 1.3 of Knockout, some control flow bindings will appear that may be useful to you. In particular, "if" or "with" bindings will work for this situation. They are described here: https://groups.google.com/d/topic/knockoutjs/pa0cPkckvE8/discussion
RP Niemeyer
source share