0
I am making a notification system and am getting the following error:
Uncaught TypeError: _.template(...).html is not a function
Follow the code here:
<script type="text/x-template" id="notifications-template">
<ul>
<%
_.each(notifications, function(notification{
if( notification.type == 1){ %>
<li><% = notification.gig.artist.name %>has canceled the gig at <% = notifications.gig.venue at <% =notifications.gig.datetime. %></li>
<%
}
}))
%>
</ul>
</script>
<script>
$(document).ready(function () {
$.getJSON("/api/notifications", function (notifications) {
$(".js-notifications-count")
.text(notifications.length)
.removeClass("hide")
.addClass("animated bounceInDown");
$(".notifications").popover({
html: true,
title: "Notifications",
content: function () {
var compiled = _.template("#notifications-template").html();
return compiled({ notifications: notifications });
},
placement: "bottom"
});
});
});
</script>
Updating
It was missing the '$' selector inside _.template($("#notificação").html()
But now I get an error in underscore.js
Uncaught SyntaxError: Unexpected token {
The function
_.template
is there? This.html()
at the end is part of it? Try to take out . html()– JuniorNunes
'#notification-template' This is appearing there in the notifications, and it was supposed to appear the notifications, and this _.template is from a library or "underscore.js"
– Márcio Eric
Welcome to Stackoverflow in English. I edited your question to remove the greetings, as we usually keep them as clean as possible to focus on your scheduling question. If you are interested in visiting a part of the site that is not aimed to ask questions can know the Stack Overflow chat in Portuguese. If you have questions about the operation, rules and procedures of the site visit the Stack Overflow in English Meta :)
– Jéf Bueno
Missed close the new parenthesis you opened
– JuniorNunes
It wasn’t like that, I’ve been trying for a while, but it’s giving n.replace is not a Function, I’ve reinstalled the library and nothing
– Márcio Eric
When you included the selector symbol ($), you closed the template method parentheses?
_.template($("#notificação").html());
– Carlos Messala Oliveira