Searched all over stackoverflow & other sources - can't seem to find anything of much help.
I have a statistical table-like UI with data driven content. The data is a huge array/object serialised on the back-end.
I am then extracting the values within that array - which are set as observables - and outputting them on the page with data-bind attributes.
The table displays the top performing artist in a given category and the two related artists below.
The problem is that we need to dynamically change the data-bind attribute so that it is capable of looking at a variable property in the data.
For example, if the user filters by "Artist", we want to display the Artist's Name (i.e
<span data-bind="text: ArtistName()"></span>
BUT
if the user filters by "Genre", we want the same part of the HTML to be able to display the Track Length (or any other arbitrary observable property) (i.e )
Ultimately, I want to have a variable data-bind attribute, like
I know that I can achieve this using a potentially huge if statement, like so:
<!-- ko if: $parent.SortMethod() == 'Topic1' -->
<span data-bind="text: Topic1()"></span>
<!-- /ko -->
<!-- ko if: $parent.SortMethod() == 'Topic2' -->
<span data-bind="text: Topic2()"></span>
<!-- /ko -->
<!-- ko if: $parent.SortMethod() == 'Topic3' -->
<span data-bind="text: Topic3()"></span>
<!-- /ko -->
...etc
Surely there is a more efficient way...?
extractingandoutputtingthem would help.