Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockoutjs simple cascading selects
    primarykey
    data
    text
    <p>I'm trying to do a simple cascading combobox using knockoutjs. My first combobox binds to 2 properties in the viewmodel:</p> <p><strong>BusinessLines</strong> as the source for comboboxoptions</p> <p><strong>SelectedBusinessLine</strong> as the selected item in the first combobox.</p> <p>Each BusinessLine has a collection of Clusters.</p> <p>The second combox should data bind to the SelectedBusinessLine.Clusters observable for combobox options source, and SelectedCluster for the selected option.</p> <p>The problems is that the second combobox doesn't get populated at all.</p> <p>Source in <a href="http://jsfiddle.net/x2qMg/2/" rel="nofollow">JsFiddle</a> (In JsFiddle the first binding doesn't work either, sry firs time use)</p> <p>JavaScript</p> <pre><code> var mainViewModel = null; $(document).ready(function() { var mainViewModelData = &lt;%= JsonConvert.SerializeObject(NewRequestViewModel) %&gt;; mainViewModel = ko.mapping.fromJS(mainViewModelData); ko.applyBindings(mainViewModel); }); </code></pre> <p>HTML</p> <pre><code>&lt;div&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; Business Line &lt;/td&gt; &lt;td&gt; &lt;select data-bind="options: BusinessLines, optionsText: 'Title', value: SelectedBusinessLine, optionsCaption: 'Select Business Line..'"&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Cluster &lt;/td&gt; &lt;td&gt; &lt;select data-bind="options: SelectedBusinessLine.Clusters, optionsText: 'Title', value: SelectedCluster, optionsCaption: 'Select Cluster..'"&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre> <p><strong>Update</strong>:</p> <p>Second <strong>solution</strong> (without computed props)</p> <pre><code>&lt;select data-bind="options: SelectedBusinessLine() ? SelectedBusinessLine().Clusters() : [], optionsText: 'Title', value: SelectedCluster, optionsCaption: 'Select Cluster..'"&gt; &lt;/select&gt; </code></pre>
    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.
    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