Your Html is like this ...
An identifier is present in your loop. You will use this value for more information (ajax).
<tbody data-bind="foreach:persons"> <tr> <td data-bind="text: id"></td> <td data-bind="text: name"></td> <td ><span data-bind="popOver: {content : $root.contentData, id: id}"</td> </tr> </tbody>
In your Model view, you have a variable - this variable is initially empty.
var contentData = ko.observable();
Add your own binding handler, for example:
> ko.bindingHandlers.popOver = { > init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { > var value = ko.utils.unwrapObservable(valueAccessor()); > > var options = { > placement: 'top', > title: "Title", > html: true, > trigger: 'manual', > content: value.content > }; > > $(element).popover(options); > > > > > $(element).click(function () { > var id = value.id(); > var response = myApp.GetAdditionalData(id); > value.content(response.content); > > $(this).popover('toggle'); > }); > } };
Outside of your view model, you will have a function making an ajax call:
var GetAdditionalDataFromAjax = function (id) { return { "content": "some content returned by id"};
source share