(function ($) {
window.AppView = Backbone.View.extend({
el: $("body"),
events: {
"click #add-friend": "showPrompt",
},
showPrompt: function () {
var friend_name = prompt("Who is your friend?");
}
});
var appview = new AppView;
})(jQuery);
el
here. Is it element? el() The Backbone. js View el method defines the element that is used as the view reference. this. el is created from the view's tagName, className, id and attributes properties, if specified.
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
Unlike most of the MVC frameworks, Backbone. js consists of six main components: Models, Views, Collections, Events, Routers and Sync.
Backend Synchronization BackboneJS is use with the front-end and back-end systems, allows the synchronization with the backend to provide support to RESTful APIs.
tagName
, className
, id
and attributes
properties of the view. If you don't specify an element, it defaults to a div
It's all in the official documentation actually...
Alladnian answered it but I would add that when using el
you can make use of $el
which is a cached jQuery object of your view element.
So you can always simply pass only the tag you wish to use (for consistency, brevity and flexibility) and then reference it as $el
to make use of it as a jQuery object.
this.$el.addClass("active");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With