I'm used to loading up partial views and user-controls from ASP.NET with some data when its requested. After seeing Knockout components, I tried to figure out how to do something similar with the documentation, but couldn't figure it out.
Can anyone help me with a quick example of how to do something simple like take a table full of data, and load up a Knockout component based on the row that was clicked?
<tbody data-bind="foreach: unapprovedNotes">
<tr>
<td><a href="#" data-bind="click: fetchNote(id())">Fetch this record</a></td>
</tr>
</tbody>
<div id="note-preview-template">
<client-information params="???"></client-information>
</div>
ko.components.register('client-information', {
viewModel: function(params) {
var self = this;
self.someProperty = params.???
},
template: { element: 'note-preview-template' }
});
self.fetchNote = function(id) {
//AJAX call that would load the data into <client-information>
}
So clicking the link would make an AJAX call to load up the component's data on demand. I don't need to load up the component at page load, but would like to reuse the component elsewhere in my application with similar behavior.
Is it even worth using components or should I just create a second viewmodel that has all the functionality wrapped in it?