Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursion on select
    primarykey
    data
    text
    <p>I have two select controls and on select I want to repopulate both select controls with new data. For example if I select one option it will call relevant subscribe function, then the new data will be passed in to "refresh" function and here it sets the new data to both selection controls, but also at this moment I get a recursion problem, which calls subscribe function again and so on, so basically I don't have any idea on how to fix this recursive call.</p> <p><strong>jsFiddle</strong> example:</p> <p><a href="http://jsfiddle.net/fWTpE/" rel="nofollow">http://jsfiddle.net/fWTpE/</a></p> <p><strong>HTML</strong>:</p> <pre><code>&lt;select class="select" data-bind="value: currentSourceOne, options: sourceOne, optionsValue: function(item) { return item; }, optionsText: function(item) { return item.text; }, optionsCaption: &amp;#39;Select&amp;#39;"&gt;&lt;/select&gt; &lt;select class="select" data-bind="value: currentSourceTwo, options: sourceTwo, optionsValue: function(item) { return item; }, optionsText: function(item) { return item.text; }, optionsCaption: &amp;#39;Select&amp;#39;"&gt;&lt;/select&gt; </code></pre> <p><strong>JS</strong>:</p> <pre><code>function ViewModel(data) { var self = this; self.refresh = function (data) { if (data.currentObject != null) { self.sourceOne(data.currentObject.sourceOne); } }; self.currentObject = ko.observable(data.currentObject); self.sourceOne = ko.observableArray(self.currentObject().sourceOne); self.currentSourceOne.subscribe(function(value) { if(value) { // omitted the code which generates new data self.refresh(data); } }); // omitted repetitive code for second select control }; $(function () { // omitted the code which generates data ko.applyBindings(new ViewModel(data)); }); </code></pre>
    singulars
    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.
 

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