how Dynamically accessing properties of knockoutjs observable array
I am using the below code for handling sort functionality. It is working for me. But is there any way to make the code as common and so i can use it whenever needed.
The code above is working fine, but i didn’t want the sorting code to be repeated.
Instead i want something like this
There’s basically two options: Have three separate functions
The second one could look something like this:
And then the custom binding for sortFunction:
Another option as mentioned by Joeseph would be to pass the property name into the click function, which would then return a function. I don’t think this is as nice an option as the custom binding, but Here’s a fiddle that does that:
And then your viewmodel would change to add the function: