Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The issue is with the way you are attaching the rendered view in the calling method.</p> <p>In the below router method</p> <pre><code>searchresults: function() { this.searchresults = new SearchResultsView({}); $('#container').empty(); $('#container').append(this.searchresults.render().el); }, </code></pre> <p><strong>You should first attach the initialised view's el to an element in the parent view and then render it</strong>. </p> <p>This is necessary because sometimes child view might search for an html element in the html created and attached within it self (as in your case). If the view is not attached before rendering, the html created while rendering will not actually be part of the windows.document and therefore not searchable (its just in memory). </p> <p>In your case, you are trying to search for an element which is not yet part of window.document.</p> <pre><code> var SearchResultsView = Backbone.View.extend({ ... drawList: function(collection) { collection.each(function(place) { window.console.log(place.get("name")); // this proves the collection is still here. But, it's not rendering? Because the DOM isn't finished rendering yet? $("ul#resultsList").append("&lt;li&gt;&lt;a href='#locationdetail/" + place.id + "' class='link'&gt;" + place.get("name") + "&lt;/a&gt;&lt;/li&gt;"); }); }, ... }); </code></pre> <p>Following change should fix the issue.</p> <pre><code> searchresults: function() { this.searchresults = new SearchResultsView({}); $('#container').empty(); $('#container').append(this.searchresults.el); this.searchresults.render(); }, </code></pre> <p>The SearchResultsView's el is now part of the window.document. Any html created and attached within the view is also part of the window.document and searchable.</p> <p>Here is the sample working html file with backbone code I wrote, based on your code.</p> <p><a href="http://jsfiddle.net/venkat_kotra/rHWPL/" rel="nofollow">http://jsfiddle.net/venkat_kotra/rHWPL/</a></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.
    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