Note that there are some explanatory texts on larger screens.

plurals
  1. PODurandal widget timing issue
    primarykey
    data
    text
    <p>i have, supposedly, a timing-problem with my durandal (v1.2) widget.</p> <p>the widget is used on multiple views and this works perfect for the very first view only.</p> <p>all other views stay disabled and company().length remains 0. the code is executed on every view, the ajax calls are finished successfully, the datacontext hits the querySucceeded method and fills the passed observableArray.</p> <p><strong>embedding the widget:</strong></p> <pre><code>&lt;div data-bind="widget: { kind: 'companypicker', companyId: selectedCompanyId }"&gt;&lt;/div&gt; </code></pre> <p><strong>the widget markup :</strong></p> <pre><code>&lt;select data-bind="options: companies, optionsText: 'displayName', optionsValue: 'id', optionsCaption: 'Choose...', value: selectedCompany, enable: companies().length &gt; 0"&gt;&lt;/select&gt; &lt;span class="loader" data-bind="css: { active: companies().length == 0 }"&gt; &lt;i class="icon-spinner icon-2x icon-spin"&gt;&lt;/i&gt; &lt;/span&gt; </code></pre> <p><strong>the widget code:</strong></p> <pre><code>define(function (require) { var ctor = function (element, settings) { var self = this; self.datacontext = require('services/datacontext'); self.settings = settings; self.selectedCompany = ko.observable(); self.companies = ko.observableArray(); self.returningCompanyId = ko.observable(settings.companyId); settings.companyId.subscribe(function (newValue) { if (!newValue) { self.selectedCompany(null); } }); self.selectedCompany.subscribe(function (newValue) { self.returningCompanyId()(newValue); }); self.datacontext.getCompanies(self.companies); }; return ctor; }); </code></pre> <p>this has some weird looking code i'm not really happy with (returning, wrapping settings in observable, etc.) but this enabled me to pass in an observable (i.e. 'selectedCompanyId'), assign a value and get notified in the viewModel of the current view without using pub/sub.</p> <p><strong>datacontext call:</strong></p> <pre><code>//datacontext construct obviously inspired by jpapa :) var getCompanies = function (companies) { var query = entityQuery.from('CompanyOverview'); return manager.executeQuery(query) .then(querySucceeded) .fail(queryFailed); function querySucceeded(data) { if (companies) { companies(data.results); } log('Successfully retrieved companies', data, true); } }; </code></pre> <p><strong>BUT:</strong> </p> <p>if i wrap the line </p> <pre><code>self.datacontext.getCompanies(self.companies); </code></pre> <p>into </p> <pre><code>setTimeout(function() { self.datacontext.getCompanies(self.companies); }, 5000); </code></pre> <p>it works on every page. my problem is now, that i just can't understand where this timing problem is coming from.</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