Im using backbone to construct my client-side app, what im trying to do is is display a joke each time the user clicks .get_joke on an event: heres my backbone app code:
JokeModel = Backbone.Model.extend({
url: '/jokes'
initialize: function() {
this.fetch();
}
});
JokeView = Backbone.View.extend({
template: _.template("<p><%= joke %></p>")
events: {
"click .get_joke" : "render"
}
render: function() {
var newJoke = new JokeModel;
$(this.el).html(this.template(newJoke.toJSON()));
}
});
newJokeView = new JokeView;
the problem when i click .get_joke it deosnt render the joke to the view, i know the the model has been fetched because i check with console.log, but it says joke hasn't been defined, but i dont't know where the problem is. thanks