I want to use something similar to the Knockout foreach construct to iterate over the properties of an object. Here is what I am trying to create...
DESIRED
Simplified answer to work with any basic object, worked for me:
<!-- ko foreach: {data: Object.keys(myObj)} -->
<span data-bind="text: $data"></span>
<span data-bind="text: $parent.myObj[$data]"></span>
<!-- /ko -->
Supposedly, there is a deeper problem (see this thread at Google groups) that is that foreach treats the object as a dictionary of parameters, not as the collection to iterate.
My best solution so far is to combined foreach
in Object.keys(myobject)
and 'with' binding context.