Why do I get, "Uncaught TypeError: Cannot read property 'events' of undefined" with this code?


#1

In my Meteor app, I’m trying to respond to right-clicks in HtmlTable cells with this JavaScript:

if (Meteor.isClient) {

  Template.scheduleTable.events({
    "contextmenu .row1Shifts": function (event) {
        return false;
    },
    "mousedown .row1Shifts": function (event) {
       if (event.button == 2) {
         console.log('row1Shifts was right-clicked');
       }
    },
    "mousedown .row1Details": function (event) {
       if (event.button == 2) {
         console.log('row1Details was right-clicked');
       }
    }
  }); //events
} // isClient

…and this HTML:

<TABLE name="sceduleTbl" id="sceduleTbl" COLS="3">
	<TR>
		<TD align="center" valign="middle"><B>DATE</B></TD>
		<TD align="center" valign="middle"><B>SHIFTS</B></TD>
		<TD align="center" valign="middle"><B>SHIFT DETAILS (How many of What, Where, and Who)</B></TD>
	</TR>
  <TR id="rowDate1">
    <th ALIGN="LEFT" rowspan="3"><input name="date1" id="date1" type="date"/></th>
		<TD class="row1Shifts" ALIGN="LEFT"><input id="timeDate1From" name="timeDate1From" type="time"/> to <input name="timeDate1To" id="timeDate1To" type="time"/></TD>
    <td class="row1Details" ALIGN="LEFT" id="rowForDate1Shift1">3 Vendors at Station A<br/>Vendor1<br/>Vendor2<br/>Vendor3</td>
	</TR>

When I run it, though, I get, “Uncaught TypeError: Cannot read property ‘events’ of undefined
Failed to load resource: the server responded with a status of 404 (Not Found)

Why?


#2

Is your HTML within a

<template name="scheduleTable">
</template>

?


#3

That’s got to be it; silly me. I was going to do that later when it got more complex, but I’ll do it now. I’m sure that is the source of my problem (no pun intended), as similar code at work works fine (with html inside a template). Thanks!