Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery eventbinding in collapsible menu while using knockout template
    primarykey
    data
    text
    <p>I have the following view in MVC , where I am trying to render a collapsible menu. </p> <pre><code>@{ ViewBag.Title = "Details"; Layout = "~/Views/Shared/_Layout.cshtml"; } @section Scripts { @Scripts.Render("~/bundles/jqueryval") &lt;script type="text/javascript" src="@Url.Content("~/Scripts/knockout-2.2.0.js")"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="@Url.Content("~/Scripts/moment.js")"&gt;&lt;/script&gt; &lt;script type="text/html" id="problemTemplate"&gt; &lt;li&gt;ID# &lt;span data-bind="text: ProblemID"/&gt; &lt;ul data-bind="template: { name: 'visitTemplate', foreach: VisitList, as: 'visit' }"&gt;&lt;/ul&gt; &lt;/li&gt; &lt;/script&gt; &lt;script type="text/html" id="visitTemplate"&gt; &lt;li&gt; Visit &lt;span data-bind="text: VisitID"&gt;&lt;/span&gt; &lt;/li&gt; &lt;/script&gt; &lt;script type="text/javascript"&gt; function MyViewModel() { var self = this; self.problems= ko.observableArray(); $.getJSON("/api/clients/1/history", self.problems); } $(document).ready(function () { ko.applyBindings(new MyViewModel()); $('#usernav').find('ul').hide(); $('li').live("click", function (e) { $(this).children('ul').toggle(); e.stopPropagation(); }); }) &lt;/script&gt; } &lt;div class="content"&gt; &lt;div id="title"&gt; &lt;h1&gt;Details &lt;/h1&gt; &lt;/div&gt; &lt;div&gt; &lt;ul id="usernav" data-bind="template: { name: 'problemTemplate', foreach: problems, as: 'problem' }"&gt;&lt;/ul&gt; &lt;/div&gt; &lt;div class="demo-section"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I get a regular list with all nodes showing. It appears that the <code>$('#usernav').find('ul').hide();</code> event is never fired after the knockout template is rendered. How do I fix this?</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