backbone-events

Backbone view event not firing - not sure why

梦想与她 提交于 2019-12-23 10:57:58
问题 I'm trying to get the click event to fire, but it's not working. Maybe someone can see something I can't. ConnectionView = GlobalView.extend({ tagName: 'div', events: { "click .social-links": "check" }, initialize: function() { this.render(); this.model.bind("change", this.render); }, render: function() { // Compile the template using underscore var template = _.template($("#connection-template").html(), this.model.toJSON()); // Load the compiled HTML into the Backbone "el" $(this.el).html

Backbone: add event listener only if doesn't already exist

一曲冷凌霜 提交于 2019-12-23 10:56:25
问题 In other words: how do I find list of events already being listened to? I'm using Backbone.on(... and Backbone.trigger(... to communicate between two Views that don't know about each other. However, the View that adds the listener is really an "item-view" for a collection and so I get many listeners added, and so I want to first check if that event is already being listened to. 10x. 回答1: The Backbone.Events object has a dictionary of events called _events So to check if some event is already

Preventing backbone zombie views

时光毁灭记忆、已成空白 提交于 2019-12-23 10:16:53
问题 Note: we are using backbone 1.0.0 I am relatively new to Backbone, and was going to through some of the code a ex co-worker wrote. Rather than copy pasting stuff blindly, I wanted to understand how he did things, and that's when I started wondering about the best way to handle zombie views. var view = new editItemView({ model: this.model }); this.ui.editItemPopup.html(view.render().el).modal({ modalOverflow: true }); This creates an instance of view and pops it up in a boostrap modal. The

Backbone View event not firing after upgrading Backbone from 0.9 to 1.2

不想你离开。 提交于 2019-12-23 01:28:09
问题 I have upgraded my web application from Backbone 0.9.10 to Backbone 1.2.1, and everything is great with one exception. See the code below: define( ['underscore', 'backbone', 'text!templates/myResults.html'], function (_, Backbone, Template) { var myView = Backbone.View.extend({ el: '#myResults', initialize: function (options) { this.targetLoc = options.targetLoc; }, events: function() { var _events = {}; _events ['show ' + this.targetLoc + ' a'] = 'tabClicked'; return _events; }, tabClicked:

listen to a collection add/change as a model attribute of a view

半腔热情 提交于 2019-12-22 09:09:40
问题 I have a Measure View, and it has an associated Measure Model, which has two collections, RepresentationsCollection and BeatsCollection. The Measure View has nested child Representation views, each with their own representation model, and all representation models share the same attribute of a reference to the Measure View's BeatsCollection. I know that if you are listening to a change event, the collection won't respond when something is added. You are supposed to use bind. The docs aren't

using a single div as a container for multiple backbone views losing event bindings

浪尽此生 提交于 2019-12-22 06:41:44
问题 Ok, so I have a navigation and the concept of a dashboard. In my router when I click on a navigation link, I'm calling on my dashboard view to set the active tab. For example: NAV <a href="#" class="dashabord_tab" id="widgets">Widgets</a> <a href="#" class="dashabord_tab" id="Foobars">Foobars</a> dashboard_container.jst.tpl <div id="nav"></div> <div id="current_tab"></div> DASHABORDVIEW DashboardView = Backbone.View.extend({ template:JST.dashboard_container, render: function(){ $(this.el)

How do I add a resize event to the window in a view using Backbone?

 ̄綄美尐妖づ 提交于 2019-12-20 18:32:48
问题 I have been trying to attach a handler to the resize event in one of my Backbone views. After doing some research I have discovered that you can only attach events to the view's element or its descendants. This is an issue for me because the visual effect I am trying to achieve is not possible using pure CSS and requires some JS to set the dimensions of the content area element based on the window minus the header element. If you are having trouble visualizing what I am trying to do, imagine

How to add a default error handler to all Backbone models?

只愿长相守 提交于 2019-12-18 19:31:57
问题 Background: Backbone model provides an option to register a fallback error handler that will be called each time a call to the server fails and no specific handler is provided. MyModel = new Backbone.Model.extend({ initialize: function(option) { this.on("error", this.fallbackErrorHandler); }, fallbackErrorHandler: function() { // default behavior in case of an error }, foo: function() { this.fetch(); // fallbackErrorHandler will be called this.fetch({ // the inline error handler will be

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

好久不见. 提交于 2019-12-18 18:53:59
问题 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(); this.render(); } ,render: function () { $(this.el).html(this.template()); return this; } ,events : { "change" : "change" ,"submit #login-form" : "login" } ,login : function( event) { event.preventDefault(); var self = this; this.model.login(true, { success: function( model) { app

Backbone.js with custom events in VIEW (events from another library)?

若如初见. 提交于 2019-12-13 04:51:50
问题 So I am using steroids.js and the library provides me with this event: document.addEventListener("visibilitychange", onVisibilityChange, false); function onVisibilityChange() { } This works if I just put it in my JS file, but how does that translate in a View with Backbone.js? How I implement this with the framework? I tried with .on in the initialize function, but it does not seem to work. 回答1: 1 - Using document as an element: var DocumentEventsView = Backbone.View.extend({ el : document,