backbone-events

delegateEvents in backbone.js

这一生的挚爱 提交于 2019-12-02 15:50:48
Can anyone please explain me what delegateEvents in backbone.js does? The documentation did not help me to understand. My exact use case is: I have a main view X with an inner view Y. They work great, but if I go to main view Z and then go back to X (reusing, not recreating) then events attached to Y child elements get lost. delegateEvents solves this but I want to understand why. Essentially, when you call .remove() it is a proxy to the jQuery remove function, which removes the element from the DOM, as well as all associated events from the event hash that were bound to the element. Backbone

Capture scroll event on div

心不动则不痛 提交于 2019-12-01 19:36:12
I'm trying to capture the scroll event within a Backbone.Marionette.CompositeView, but without success. As an exercise, I'm rewriting http://www.atinux.fr/backbone-books/ using Backbone.Marionette. As you can see, when you scroll down, more books are fetched and displayed (i.e. infinite scroll). However, I'm unable to capture the scroll event on my view. Here's my (simplified) code: LibraryView = Backbone.Marionette.CompositeView.extend({ // properties, initializer, etc. events: { 'scroll': 'loadMoreBooks', 'click': 'loadMoreBooks' }, // some functions loadMoreBooks: function(){ console.log(

How can I “bubble up” events on nested Backbone collections?

泪湿孤枕 提交于 2019-12-01 15:27:31
I have a Backbone app that uses nested collections (at least that's how I think they're called). In my particular case there are tabs and subtabs , and each tab (model) contains a collection of subtab (model). For those who're more familiar with code, I'll write bellow my models and collections, and how subtabs are nested inside the tab model: // Subtab Model var Subtab = Backbone.Model.extend({ defaults: { label: undefined } }); // Subtabs Collection var Subtabs = Backbone.Collection.extend({ model: Subtab }); // Tab Model var Tab = Backbone.Model.extend({ defaults: { label: undefined,

Display selected model from sidebar in information bar

不问归期 提交于 2019-12-01 11:05:45
I'm working on a application which has sidebar on the right side. That displays collection. Each model of the collection has select behavior. In the top center of the page I have one independant backbone view which acts like "info bar" and this view should update it's infomation when I select one of the views in the sidebar How can I do it? I think that the each view in the sidebar should have "selected" event with model argument, and my question is how can I listen that change in my info bar view in Backbone.js??? This sounds like something that would be served well by an event aggregator

Display selected model from sidebar in information bar

吃可爱长大的小学妹 提交于 2019-12-01 07:27:33
问题 I'm working on a application which has sidebar on the right side. That displays collection. Each model of the collection has select behavior. In the top center of the page I have one independant backbone view which acts like "info bar" and this view should update it's infomation when I select one of the views in the sidebar How can I do it? I think that the each view in the sidebar should have "selected" event with model argument, and my question is how can I listen that change in my info bar

How to find the Id of model corresponding to clicked item?

◇◆丶佛笑我妖孽 提交于 2019-12-01 02:55:51
问题 How to know the Id of item I clicked? my code is given below: $(function() { ipl.mvc.view.openings_view = ipl.mvc.view.view_base.extend({ template: '/assets/t/plmt/companies.tmpl.html', ID: '#tmpl_openings', events: { "click #edit": "editpost" }, initialize: function() { var _this = this; _.bindAll(this, 'addOne', 'addAll', 'render', 'editpost'); _this.loadTemplate(_this.template, function() { _this.model = new ipl.mvc.model.companies_model([]); _this.model.view = _this; _this.model.bind(

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

本小妞迷上赌 提交于 2019-11-30 17:27:33
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.alertSuccess( "User logged in"); self.render(); } ,error: function( model, response) { app.alertError("Could not

Backbone.js - fetch method does not fire reset event

南笙酒味 提交于 2019-11-30 13:38:22
问题 I'm beginning with Backbone.js and trying to build my first sample app - shopping list. My problem is when I fetch collection of items, reset event isn't probably fired, so my render method isn't called. Model: Item = Backbone.Model.extend({ urlRoot : '/api/items', defaults : { id : null, title : null, quantity : 0, quantityType : null, enabled : true } }); Collection: ShoppingList = Backbone.Collection.extend({ model : Item, url : '/api/items' }); List view: ShoppingListView = Backbone.View

Backbone.js - fetch method does not fire reset event

风流意气都作罢 提交于 2019-11-30 07:44:43
I'm beginning with Backbone.js and trying to build my first sample app - shopping list. My problem is when I fetch collection of items, reset event isn't probably fired, so my render method isn't called. Model: Item = Backbone.Model.extend({ urlRoot : '/api/items', defaults : { id : null, title : null, quantity : 0, quantityType : null, enabled : true } }); Collection: ShoppingList = Backbone.Collection.extend({ model : Item, url : '/api/items' }); List view: ShoppingListView = Backbone.View.extend({ el : jQuery('#shopping-list'), initialize : function () { this.listenTo(this.model, 'reset',

Can't get Backbone routes without hashes?

和自甴很熟 提交于 2019-11-30 07:28:35
I want to have bookmarkable URLs that the browser can capture and handle. If I just use Backbone.history.start() , then I can use hash URLs, like /#accounts . But I want URLs without the hashes, a la /accounts . But I can't get this to work using Backbone.history.start( { pushState: true } ) ( as others have described it ). My routes are straightforward, and taken directly from the documentation . MyRouter = Backbone.Router.extend({ routes: { '/accounts': 'accounts', } }); I'm using Chrome (also tried with FF), and the behaviour is that an /accounts request goes straight to the server. Not