(Using KnockoutJs 2.0.0)
I have a list of phone numbers in my view model. Each phone number has a type (home, work, mobile, etc.). I want an icon (based on the font class) to be displayed next to each phone number.
If I hardcode the icons in the css binding, everything works:
<tbody data-binding="foreach: phoneList">
<tr>
<td><span data-bind="css: {'icon-home' : TypeId() == 1, 'icon-building': TypeId() == 2, ... , 'icon-phone': TypeId() >= 7></span></td>
...
</tbody>
I wanted to replace the hardcoded list with a function call. At first I tried to add the function to the parent, but was not successful, so I tried to add the function directly to the phone object as a function and how ko.computed(), but none of them work for me.
I came up with the code here that demonstrates the problem. If you check the span element of table elements, you will almost see it as if waiting for the data processes the returned string as an array of characters and sets the class based on indexes, rather than treating the returned string as a class.
I am sure that this is something completely obvious, but I beat my head to no avail.
source
share