backbone-events

backbone.js events and el

走远了吗. 提交于 2019-12-04 18:35:26
问题 Okay, so I've read several other questions regarding Backbone views and events not being fired, however I'm still not getting it sadly. I been messing with Backbone for about a day, so I'm sure I'm missing something basic. Here's a jsfiddle with what I'm working with: http://jsfiddle.net/siyegen/e7sNN/3/ (function($) { var GridView = Backbone.View.extend({ tagName: 'div', className: 'grid-view', initialize: function() { _.bindAll(this, 'render', 'okay'); }, events: { 'click .grid-view': 'okay

In Backbone.js, why do silent changes trigger change events eventually?

只谈情不闲聊 提交于 2019-12-04 08:52:25
问题 When I pass {"silent":true} while setting an attribute in a Backbone model, why doesn't that just suppress the change:attribute event? What is the advantage of firing that event the next time an attribute is changed? Update Backbone 0.9.10 changed the behavior of passing { "silent": true } . From the changelog: Passing {silent:true} on change will no longer delay individual "change:attr" events, instead they are silenced entirely. Browse the changelog here 回答1: This has confused me for some

Backbone events on model firing on collection (Double firing)

只愿长相守 提交于 2019-12-04 06:28:17
A Backbone app which I'm developing has a collection and a model, and associated views for each item. https://gist.github.com/2255959 When I click on the PostView, unexpectedly, the event fires on the collection without any wiring. I figured I'd need to bind an event to the model, then have that fire an event on the collection. Is that not the case? Does a collection automagically inherit events fired its child models? I'm uncertain, but I think it has something to do with the nested views, and maybe the event is being bound on both places instead of just the inner el . From the fine manual :

Why does Backbone.js model's 'on()' take 'this' as last parameter if it's almost always going to be this?

好久不见. 提交于 2019-12-03 20:12:09
I'm just getting into Backbone, and one thing that I don't understand is why the 'on()' method for models always takes three arguments--event, handler, and context. It seems that almost always 'this' is used for context and I haven't seen any other usage. Even if there were, since I haven't seen one yet it must be pretty rare. So my question is: When does one use a context other than 'this', and why is Backbone designed this way? By the way, I do understand why you need to provide context, it's just that I wonder why the method syntax specifies that I use three arguments instead of making the

Using backbonejs view, what is the best way to attach an “onload” event to an image tag?

喜夏-厌秋 提交于 2019-12-03 17:02:57
问题 I want to attach an "onload" event for an image in a backbonejs view. I am currently including it in the "events" as "load img":"function", but it is not getting fired off. Any suggestions for doing this? 回答1: Backbone's event handling is based on delegate and delegate can only be used with events that bubble. The problem is that load events do not bubble; from the HTML5 specification: If the download was successful Set the img element to the completely available state, update the

Binding multiple event types in backbone views

≡放荡痞女 提交于 2019-12-03 14:39:04
问题 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': 'doSomething' }, doSomething: function(e) { console.log(e.type); } }); Basically what I am wondering is if it is possible to combine the event binding for 'click' and 'touchstart' into one line - along the lines of: events: { 'click,touchstart .bar': 'doSomething' } Any

Passing arguments to events in backbone

隐身守侯 提交于 2019-12-03 07:20:43
问题 First of all, I did some search and no answer on stackoverflow/google provided me the thing I wanted. Here's a snippet of my code: //in the view this.collection.on("add",triggerthis) this.collection.add(predefinedModel) triggerthis: function(a, b, c, d){ //etc. } Basically, I want to be able to pass an argument on add and receive the argument in triggerthis. Is this possible? Thanks in advance. 回答1: You can't do this the way you want without using undocumented features. If we have a look at

Using backbonejs view, what is the best way to attach an “onload” event to an image tag?

不问归期 提交于 2019-12-03 05:56:55
I want to attach an "onload" event for an image in a backbonejs view. I am currently including it in the "events" as "load img":"function", but it is not getting fired off. Any suggestions for doing this? mu is too short Backbone's event handling is based on delegate and delegate can only be used with events that bubble. The problem is that load events do not bubble; from the HTML5 specification : If the download was successful Set the img element to the completely available state, update the presentation of the image appropriately, and fire a simple event named load at the img element. And a

Binding multiple event types in backbone views

那年仲夏 提交于 2019-12-03 04:25:22
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': 'doSomething' }, doSomething: function(e) { console.log(e.type); } }); Basically what I am wondering is if it is possible to combine the event binding for 'click' and 'touchstart' into one line - along the lines of: events: { 'click,touchstart .bar': 'doSomething' } Any suggestions would be appreciated. rinat.io It's impossible for views jQuery events, which are bound

delegateEvents in backbone.js

拈花ヽ惹草 提交于 2019-12-03 02:20:10
问题 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. 回答1: Essentially, when you call .remove() it is a proxy to the jQuery remove function, which removes the element