I have a ViewModel that looks like:
{
empName: [
{ name: 'NAME1' },
{ name: 'NAME2' }
]
}
I want to display different department names according to my empName
while looping through name
property using a switch statement.
such that output is:
Department 1
Department 2
I tried the following:
<ul data-bind="foreach: empName">
<div data-bind="switch: name">
<div data-bind="case: 'Name1'">
Department 1
</div>
<div data-bind="case: 'Name2'">
Department 2
</div>
<div data-bind="case: $default">
</div>
</div>
But I get the following output:
Department 1
Department 2
Department 1
Department 2
How can I achieve this?