I use in my application KockoutJS External Template Engine to be able to load external templates files(so i can use them again in many pages). It's works good and i could use templates in another folder and data displayed correctly
My problem is that i want to call some function after my template is fully rendered and i used this solution with custom bindings (thanks to @RP Niemeyer).
The problem is that custom binding is executed before the template html is fully rendered when using external template file.
But using template which is existed inside my html page the custom binding is executed after the template html is fully rendered.
My template:
<script type="text/html" id="report-template">
<li>
<a href="#" data-bind="text: Name, click: $root.ReportsViewModel.ShowParameters"></a>
<ul data-bind="template: { name: 'report-template', foreach: childItems }">
</ul>
</li>
</script>
and that's how i call my custom binding jsTree
<div id="reports-tree">
<ul data-bind="template: { name: 'report-template', foreach: $root.ReportsViewModel.Reports }, jsTree: $root.ReportsViewModel.Reports"></ul>
</div>
and that's my custom binding code:
ko.bindingHandlers.jsTree = {
update: function (element, valueAccessor) {
var reports = ko.utils.unwrapObservable(valueAccessor());
if (reports.length > 0) {
$(element).parent().jstree({
"themes": {
"theme": "default",
"dots": false,
"icons": true,
"utl": "/jstree-style.css"
},
"plugins": ["themes", "html_data"]
});
}
}
}