Last active
August 29, 2015 13:57
-
-
Save MatthewVita/9586826 to your computer and use it in GitHub Desktop.
KOTemplateLoader.js - Loader that easily renders external Knockout.js templates [jQuery dependency]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* @desc: loads an external | |
* HTML Knockout.js template | |
* file, places it in the DOM, | |
* and applies the KO bindings | |
* | |
* @param: tmplFile - the template | |
* file | |
* | |
* @param: targetElem - the target | |
* element's id or class | |
* | |
* @param: viewModelInst - instance of | |
* the relative view model object | |
*/ | |
function loadExternalKoTemplate(tmplFile, targetElem, viewModelInst) { | |
$.get(tmplFile) | |
.success(function(data) { | |
$(targetElem).html(data); | |
ko.applyBindings(viewModelInst, $(targetElem)[0]); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment