I want to display multi dimentional ko observable array data in html. But, i didn't get output.
My code :
<!-- ko if: ($parent.cust_opt_avail() === 1) -->
<!-- ko foreach: $parent.customVal() -->
<div class="product-custom-option-select">
<p class="options-label" data-bind="text:key"></p>
<p class="options-label" data-bind="text:custom_option_select_text"></p>
</div>
<!-- /ko -->
<!-- /ko -->
cust_opt_avail() is ko observable variable. customVal is ko observable array.
output of customVal is :
I want to display custom_option_select_text and display key name on first p tag.
How to do it ?
Expected Result :
please help me.
From your previous question and comments in this question, I gather you're setting an object to
ko.observableArray()
. This is not correct. You should set acustomVal
to ako.observable()
. Then useObject.keys()
and use aliasing in yourforeach
binding.NOTE:
Since
customVal
is in a nested context, you might have to add another$parent
prefix to all the inner bindings.Interesting question! So you want to do a for loop through
customVal()
, butcustomVal()
itself has arrays. In this case it is useful to know about Knockout binding context. Particularly$data
. You can use it as a reference to the current context that you're in, and not worry about the names like Color and Size.Once you use
$data
as a placeholder for Color and Size arrays, do a for loop through them as well. I've created a snippet: