Note that there are some explanatory texts on larger screens.

plurals
  1. POknockoutJS - select default template on init
    primarykey
    data
    text
    <p>is it possible to pre-select a template before one will be selected in the menu. For example if I have the following knockoutJS Code: <a href="http://jsfiddle.net/rqa8P/15/" rel="nofollow">http://jsfiddle.net/rqa8P/15/</a> </p> <pre><code>// ---------------------------------------------------------------------------- // View var View = function(page, templateName, data) { var self = this; self.page = page; self.templateName = templateName; self.data = data; //animations between page changes this.animatePageChange = function() { $('.wrapper').hide(); $('.wrapper').fadeIn(3000); //init function for each main menu view model //alert(self.data.init()); }; //animations between sup page changes this.animateSubPageChange = function() { $('.content').hide(); $('.content').fadeIn(3000); //init function for each sub menu view model //alert(self.data.init()); } }; // ---------------------------------------------------------------------------- // SubPage1ViewModel (Subpage from Main Page View 1) var SubPage1ViewModel = { init: function() {return("SubPage1ViewModel init")}, somedata : ko.observable("Here comes some data!") }; // ---------------------------------------------------------------------------- // SubPage2ViewModel (Subpage from Main Page View 1) var SubPage2ViewModel = { init: function() {return("SubPage2ViewModel init")}, somedata : ko.observable("Here comes some data!") }; // ---------------------------------------------------------------------------- // SubPage3ViewModel (Subpage from Main Page View 1) var SubPage3ViewModel = { init: function() {return("SubPage3ViewModel init")}, somedata : ko.observable("Here comes some data!") }; // ---------------------------------------------------------------------------- // MainPage1viewModel (Menu Page) var MainPage1viewModel = { //Sub Pages subpage1view : new View("subpage1", "subpage1Tmpl", SubPage1ViewModel), subpage2view : new View("subpage2", "subpage2Tmpl", SubPage2ViewModel), subpage3view : new View("subpage3", "subpage3Tmpl", SubPage3ViewModel), //make the selected sub page observable selectedView : ko.observable(), init: function() {return("MainPage1viewModel init")} }; // ---------------------------------------------------------------------------- // MainPage2 View (Main Menu) var MainPage2viewModel = { //init function init: function() {return("MainPage2viewModel init")}, somedata : ko.observable("Here comes some data!") }; // ---------------------------------------------------------------------------- // ControlViewModel (cvm), var cvm = { //Main Pages mainPage1view : new View("mainpage1", "mainPage1Tmpl", MainPage1viewModel), mainPage2view : new View("mainpage2", "mainPage2Tmpl", MainPage2viewModel), //make the selected page observable selectedView : ko.observable(), }; //bind the cvm view model to the index.html ko.applyBindings(cvm); </code></pre> <p>My goal is when the page is loaded that the Main Page 2 Template is already loaded into the dom and if I click to the Main Page 1 then it should be immediately loaded with the SubPage1 content. At moment there is always a site before...</p> <p>greetings!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload