How to get an observableArray’s length


I am attempting to create an array of contract line items (CLINs) that will be displayed as individual div elements below a header of general contract information.

I am able to get the normal observables to work, but it appears that the passing of the array via the constructor for the view model is not creating any part of the clins observable array.

I have a jsFiddle that illustrates my problem. What is strange to me is that the data-bind="text: clins.length() on the HTML span tag does not even return zero, but instead renders nothing.

Is there anyway to enable debugging within a jsFiddle or should I see a warning/error?

Best Solution

Errors from jsfiddle pages do get sent to your browser.

As for your error, try this:

<span data-bind="text: clins().length">

This turns the observableArray into an array and uses the array's length property.

See the updated the jsfiddle as well.

Related Question