Onload Binding using knockoutjs?
13,961
Solution 1
It sounds like you are refreshing page content through an AJAX call and you want to make that AJAX call on the page load in ADDITION to binding it to an event.
Assuming that is the case, at the end of your ModelViewModel declaration, simply call the function. For example:
function SearchResultsViewModel(){
this.updateResults=function(){
//Some AJAX Call and action.
}
this.updateResults();
}
Solution 2
You bind the knockout viewmodel to the view as normal, then use
window.onload = function ()
{
//data from to another place in the load
}
or in jQuery
$(document).ready(function(){
//data from to another place in the load
)};
Since knockout is bound to the view, when you add items, the view will update automatically.
Author by
BlaShadow
Mobile software developer who love to write JavaScript.
Updated on June 04, 2022Comments
-
BlaShadow almost 2 years
I Want to execute a function when the page load but don't know how to do it. cause that I have a list but his data from to another place in the load.