Why can't Template.find locate this LI tag?

I must be missing something really stupidly simple. Given this code:

<ul class="items">
  {{#each listOfItems}}
    <li>Thing {{name}}</li>
  console.log(this.find('ul.items > li'));

I’m getting a null returned by console.log. Why??


Ok, I’ve figured out it’s because the {{#each}} statement is still dumping out data after onRendered gets called. Is there some callback I can use after all data on a page is done printing?

if listOfItems is coming from a collection in the db, then you can wait for the subscription to be ready in a Tracker.autorun and then execute your code

Aha! I see.

I went with this code in the template onRendered:

var template = this;

template.subscribe('listOfItems', {
  onReady: function() {
    console.log(template.$('ul.items > li'));

The problem was that I was subscribing to the publication on a more global level, and had no way of waiting for it to be ready.