Questions tagged [backbone-views]

Views in the Backbone.js library. Backbone views are used to reflect what your applications' data models look like. They are also used to listen to events and react accordingly.

Docs

1114 questions
98
votes
3 answers

Backbone.View "el" confusion

How should a view's el be handled? It has to be set, otherwise events don't fire (see here). But should it be an element that is already on the page? In my app, I render a (jQuery Templates) template into a Fancybox. What should the el be in that…
Manuel Meurer
  • 3,238
  • 6
  • 35
  • 50
72
votes
4 answers

attaching backbone.js views to existing elements vs. inserting el into the DOM

I am implementing my first actual non-tutorial Backbone app, and have 2-ish questions about an aspect of using using backbone.js that isn't settling very well with me, which relates to injecting a view's rendered el into the DOM vs. using an…
B Robster
  • 40,605
  • 21
  • 89
  • 122
61
votes
4 answers

What is the difference between $el and el in Backbone.js views?

Can you please tell the difference between $el and el in Backbone.js views?
ali asad
  • 1,329
  • 4
  • 17
  • 23
45
votes
7 answers

Backbone JS: can one view trigger updates in other views?

In my simple project I have 2 views - a line item view (Brand) and App. I have attached function that allows selecting multiple items: var BrandView = Backbone.View.extend({ ...some code... toggle_select: function() { …
mvbl fst
  • 5,213
  • 8
  • 42
  • 59
28
votes
3 answers

Binding multiple event types in backbone views

I was wondering if it is possible to bind multiple event types in backbone within a single line. Consider the following: var MyView = Backbone.View.extend({ id: 'foo', events: { 'click .bar': 'doSomething', 'touchstart .bar':…
stephenmuss
  • 2,445
  • 2
  • 20
  • 29
25
votes
2 answers

How can I attach 2 handlers to the same event?

I can attach handlers to Backbone Views like: var TodoView = Backbone.View.extend({ events: { "xxx": "eventHandler1" "yyy": "eventHandler2" } }); But what if I want to attach more than 1 handler to the same event? var…
jm2
  • 763
  • 2
  • 13
  • 27
24
votes
2 answers

backbone remove view deletes the el

I am creating a single page application, and I am quite new to backbone. I have a problem with creating multiple views which uses the same wrapper-div. My setup: I have added a close function to all views: Backbone.View.prototype.close =…
swenedo
  • 3,074
  • 8
  • 30
  • 49
22
votes
3 answers

Is it possible to stop Backbone "read" requests

I have a backbone application that has a number of views. Switching between views triggers Ajax requests to get different collections. I would like to stop the current "read" ajax request if a new one is started. Is it possible?
Xerri
  • 4,916
  • 6
  • 45
  • 54
20
votes
3 answers

Backbone trigger two methods in one event

I am using Backbone and I have a view with events defined: .... events: { 'click .search-button': 'setModelTerm', 'change .source-select': 'setModelSourceId', 'change .source-select': 'activateSource' }, …
Naor
  • 23,465
  • 48
  • 152
  • 268
16
votes
5 answers

Backbone and document.title

I'm creating a single page application with backbone.js and would like to know the best way to handle changing the title. I was thinking of having a 'title' option in the view and have the router (somehow) get set the document.title. Has anyone…
Xerri
  • 4,916
  • 6
  • 45
  • 54
15
votes
4 answers

Backbone.js: Fetch a collection of models and render them

I am learning JavaScript MVC application development using Backbone.js, and having issues rendering model collection in the view. Here's what I want to do: After the page finishes loading, retrieves data from the server as model collection Render…
hyde
  • 2,525
  • 4
  • 27
  • 49
15
votes
3 answers

How do I get backbone to bind the submit event to a form?

I'm using the following code to create the view: LoginForm = Backbone.View.extend({ tagName :"form" ,id : "login-form" ,className :"navbar-form" ,initialize: function () { this.model = new StackMob.User(); …
Jim Barrows
  • 3,634
  • 1
  • 25
  • 36
14
votes
1 answer

How to get attributes from the clicked element in backbone event?

Here is my basic backbone view for changing routes. I would like to get the href attribute of the clicked link. How to do that? Here is a code bellow: var Menu = Backbone.View.extend({ el: '.nav', events: { 'click a'…
hjuster
  • 3,985
  • 9
  • 34
  • 51
13
votes
1 answer

Backbone.js view instance variables?

I'm learning Backbone.js and am trying to figure out whether it's possible to have instance variables in Backbone views. My goal is to load a view's templates from an external file when a view is being instantiated. Currently I'm storing them in a…
Ville
  • 4,088
  • 2
  • 37
  • 38
13
votes
2 answers

Backbone collection fetches data, but doesn't set models

I'm trying to populate my Backbone collection from a local API and change the view to show the data. The fetch() call in my collection seems to succeed, and grabs the data, but the fetch operation doesn't update the models in the collection. This is…
And Finally
  • 5,602
  • 14
  • 70
  • 110
1
2 3
74 75