I want to build my own listView with selectedItem and Itemsource.
I have started a jsFiddle http://jsfiddle.net/andersb79/53xRL/1/
Can you please help me in the right direction about how I should build this. I havn't seen a bindingHanlder that do this.
What I want is something like this.
data-bind="myListView : { items : comments, selectedItem : selectedComment}"
In your custom binding you need to:
I've also highlighted the current selected item for clarity.
Here's a working example
Note: As I am using the
update
instead of theinit
method it will work when updating the list of commentsUpdate
If you want to use the contents of the original DIV as the template for each created item, you need two additional steps:
Apply bindings to the created element before adding it to the DOM
};
Note that we have to prevent the content of the div being processed by knockout by returning
{ controlsDescendantBindings: true }
from ourinit
method.Here is an updated example