Please look at my view model below:
viewModel = [
{
StudentName : 'Ronald',
Reviews : [ '3/5', '2/5', '4/5'],
TeacherNames : [ 'Nema', 'Sarah', 'Vilson']
},
{
StudentName : 'Chris',
Reviews : [ '4.5/5', '2.5/5', '3.5/5'],
TeacherNames : [ 'Nema', 'Sarah', 'Vilson']
}
]
In below HTML I am trying to display Reviews in nested foreach structure. Reviews display as per expectation. but how can I place TeacherNames along with that single review? I have put the TeacherNames[$index], but it doesn't work.
Note 1: Number of elements in both the array(i.e. Reviews and TeacherNames) will be same.
Note 2: I don't want to change the structure of this JSON model, something like putting extra variable and placing both the parameters in one array.
<div data-bind="foreach:viewModel">
<span data-bind="text: StudentName"></span>
<ul data-bind="foreach:Reviews">
<li>
<a href="#" data-bind="text:$data">Inbox </a>
<span class="ui-li-count" data-bind="text:TeacherNames[$index]">123</span>
</li>
</ul>
</div>
Please check this Fiddle .