I show a modal view of libraryPrep objects in my template like this:
if (_.isUndefined(this.libraryPreps)) {
this.$el.html(this.template({ }));
} else {
this.$el.html(this.template({ libraryPreps: this.libraryPreps.toJSON() }));
}
The else statement works when I have a libraryPreps object. In my template, I use it like this:
<select id="libraryPreps" >
<% if (!_.isUndefined(libraryPreps)) { %>
<% _.each(libraryPreps, function (libraryPrep) { %>
<option value="<%=libraryPrep.id%>"><%= libraryPrep.name %></option>
<% }); %>
<% } %>
</select>
When I don't have a libraryPreps object, I don't get my template to render and I get an error on the console that libraryPreps is undefined. Am I checking for undefined incorrectly in my template? I feel like I'm checking it the same way in my backbone modal view, but for some reason, in my actual template, it doesn't seem to work. Is my template notation correct? Thanks.