Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to control order of view activation in Durandal
    primarykey
    data
    text
    <p>I am building an application with Durandal 2.0.<br> My shell view looks like this:</p> <pre class="lang-html prettyprint-override"><code>&lt;div&gt; &lt;header id="nav" data-bind="compose: 'viewmodels/nav', activate: false"&gt; &lt;/header&gt; &lt;section id="content" class="main container-fluid" data-bind="router: { transition: 'entrance' }, activate: false" style="overflow: auto"&gt; &lt;/section&gt; &lt;footer&gt; &lt;!--ko compose: {view: 'footer'} --&gt;&lt;!--/ko--&gt; &lt;/footer&gt; &lt;/div&gt; </code></pre> <p>In the nav section, I want to have my tabs and a drop-down list of users (both of which are retrieved from a web service). Selecting a user from the dropdown will navigate to a new URL which will update the content section. <em>(the route looks something like localhost/#user1/tab2).</em> </p> <ul> <li><strong>Problem:</strong> I need to know the selected user from the nav section before I can retrieve the data for the content section, but the content section is activating before I have retrieved the users. </li> </ul> <p>This is really only an issue for the initial page load, since the user list is only retrieved once. </p> <ul> <li>Is there a way to tell the content section to wait until the nav section is done loading? </li> <li>Is there a better way to go about this than what I'm doing?</li> </ul> <p>The nav activate function looks like this:</p> <pre class="lang-html prettyprint-override"><code>function activate(context) { return dataservice.getUsers().then(function () { //do stuff }); }); </code></pre> <p>This activate function gets called first, and dataservice.getUsers() is called, but then the activate function of the content module gets called before the "do stuff" part happens (and before the data from the getUsers call is returned in the dataservice). Maybe there's a problem with my promises?</p> <p><strong>Edit</strong><br> I've put together a dFiddle with some actual code that shows what I'm talking about: <a href="http://jerrade.github.io/dFiddle-2.0/#test/dashboard" rel="nofollow">http://jerrade.github.io/dFiddle-2.0/#test/dashboard</a><br> The code is here: <a href="https://github.com/jerrade/dFiddle-2.0" rel="nofollow">https://github.com/jerrade/dFiddle-2.0</a> </p> <p>nav.js </p> <pre class="lang-html prettyprint-override"><code> function activate(context) { console.log('Nav View Activated'); if (vm.impersonateUsername == undefined) vm.impersonateUsername = getUsernameFromWindowLocation(); return dataservice.getPageDetailForEmployee(vm.loggedInUsername, vm).then(function () { console.log("Page details retrieved"); // I want to do something here before the dashboard activates. }); } </code></pre> <p>dashboard.js </p> <pre class="lang-html prettyprint-override"><code> function activate(username) { console.log('Dashboard View Activated'); //vm.username = nav.selectedImpersonateEmployee().Username; return dataservice.getDashboard(nav.impersonateUsername, dashboard); } </code></pre> <p>Open the page and watch the console. You'll see (among other things)</p> <pre class="lang-html prettyprint-override"><code>Nav View Activated Dashboard View Activated Page details retrieved </code></pre> <p>What I really want is for the Page details to be retrieved before the Dashboard view activates. I've actually rejiggered things so that this isn't currently a problem anymore, but it may crop again down the road.</p> <p>It doesn't seem like what I'm trying to do should be this complicated. Unless I'm pounding a square peg into a round hole here?</p>
    singulars
    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.
 

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