What exactly is this.el in Backbone.js views?

Rob

I'm confused about the meaning of el in Backbone views. Some tutorials (such as this one) make it seem like el is the parent of the view being created, where the render method is supposed to append the view to its el. Others (like this) treat it like it's the element of the view itself. Is there a best practice concerning this?

acjay

el is definitely the element the view corresponds to, not its parent. In your first example, they considering the whole page body to be the view, and then upon rendering, they insert the components that compose it. I suppose this might be appropriate for top-level views representing entire pages. Backbone gives you a lot of flexibility (i.e. rope to hang yourself with), so you can do things in many ways. Generally speaking, however you do it, it works best if you actually construct and append the components of your view before attaching it to the DOM wheverer possible. This is mentioned in your second example, and in the Backbone docs themselves:

All views have a DOM element at all times (the el property), whether they've already been inserted into the page or not. In this fashion, views can be rendered at any time, and inserted into the DOM all at once, in order to get high-performance UI rendering with as few reflows and repaints as possible.

Projects like Marionette implement a lot of Backbone best practices and let you operate at a higher level of abstraction. I highly recommend checking it out, instead of trying to figure out all the best-practice patterns yourself.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What exactly is this.el in Backbone.js views?

From Dev

Adding views to different el based on condition in Backbone.js

From Dev

What is the order of events binded by Views in Backbone.js?

From Dev

Backbone JS, navigating different views

From Dev

What exactly is #{component} in EL?

From Dev

Backbone views not rendering without predefined el specified

From Dev

Backbone.js views and models correlation?

From Dev

how to switch views with the backbone.js router?

From Dev

Backbone.js is not rendering views properly

From Dev

Views and appending table rows in backbone.js

From Dev

Backbone JS - Combination of collection, views and models

From Dev

Backbone.js is not rendering views properly

From Java

What is the purpose of backbone.js?

From Dev

Backbone - bind multiple views on one $el (events are duplicated)

From Dev

Backbone.js parent vs. child views

From Dev

Re-rendering backbone.js views on resize?

From Dev

Is it an anti-pattern to instantiate models in views in Backbone.js?

From Dev

How to load multiple Backbone.js views on a single page

From Dev

Passing Data to Views in Backbone Js does not see in the browser

From Dev

backbone js view event binding only to views elements

From Dev

Best way to start a backbone.js app with multiple views and routes

From Dev

Using backbone-validation.js on a model without views

From Dev

Backbone.js views will not display on page load, but works with jQuery in console

From Dev

Backbone.js multiple views, one collection, one fetch

From Dev

How to redirect to other views after file download using backbone js?

From Dev

What are dynamic views in Angular JS?

From Dev

Confusing this.el in backbone.js with subviews

From Dev

What to use instead of "this" in Backbone.js?

From Dev

Using Backbone.js depended views, models, views' render funcs, listening to events, from another View

Related Related

  1. 1

    What exactly is this.el in Backbone.js views?

  2. 2

    Adding views to different el based on condition in Backbone.js

  3. 3

    What is the order of events binded by Views in Backbone.js?

  4. 4

    Backbone JS, navigating different views

  5. 5

    What exactly is #{component} in EL?

  6. 6

    Backbone views not rendering without predefined el specified

  7. 7

    Backbone.js views and models correlation?

  8. 8

    how to switch views with the backbone.js router?

  9. 9

    Backbone.js is not rendering views properly

  10. 10

    Views and appending table rows in backbone.js

  11. 11

    Backbone JS - Combination of collection, views and models

  12. 12

    Backbone.js is not rendering views properly

  13. 13

    What is the purpose of backbone.js?

  14. 14

    Backbone - bind multiple views on one $el (events are duplicated)

  15. 15

    Backbone.js parent vs. child views

  16. 16

    Re-rendering backbone.js views on resize?

  17. 17

    Is it an anti-pattern to instantiate models in views in Backbone.js?

  18. 18

    How to load multiple Backbone.js views on a single page

  19. 19

    Passing Data to Views in Backbone Js does not see in the browser

  20. 20

    backbone js view event binding only to views elements

  21. 21

    Best way to start a backbone.js app with multiple views and routes

  22. 22

    Using backbone-validation.js on a model without views

  23. 23

    Backbone.js views will not display on page load, but works with jQuery in console

  24. 24

    Backbone.js multiple views, one collection, one fetch

  25. 25

    How to redirect to other views after file download using backbone js?

  26. 26

    What are dynamic views in Angular JS?

  27. 27

    Confusing this.el in backbone.js with subviews

  28. 28

    What to use instead of "this" in Backbone.js?

  29. 29

    Using Backbone.js depended views, models, views' render funcs, listening to events, from another View

HotTag

Archive