Knockout JS can easily integrate with any of the open source frameworks seamlessly to achieve the business requirement. For external data access, we can use jQuery methods such as $.getJSON()
and $.post()
to populate the content from external source, or invoke jQuery animation methods for onscreen animations.
For example, if your HTML element has to load employee information from an external sourceon
button click, call a Knockout function first, within which you can invoke jQuery methods, as follows:
- The following code is the HTML part:
<p><button data-bind='click: loadEmployee'>Load Data </button></p>
- JavaScript:
self. loadEmployee = function() { $.getJSON("/get-employee", function(data) { employeeViewModel.firstName=data.firstName; }); }