backbone-events

Overwriting a Backbone Models Change Event

拟墨画扇 提交于 2019-12-09 16:24:00
问题 I think what I want to do is pretty simple I just don't know how to do it. I would like to fire my own event when one of my models attributes changes for the purpose of passing some data to the event handler (whether the change was an increase or decrease in value). Basically I want my handler to do this in the view handler: function(increased) { if(increased) { alert("the value increased") } else { alert("the value decreased") } } // ... this.model.on("change:attr", this.handler, this); 回答1:

Backbone. Dispatch/listen to events between views

不羁的心 提交于 2019-12-09 05:18:44
问题 Im a bit confused over how to handle events between views in Backbone. Right now i have two partial views rendered at the same time on a website. Now i want one of the views to dispatch an event that the other view can listen to. How would i do that? In the view that dispatches the event i run: this.trigger("myEvent") And in the view listening i run: this.bind('myEvent', this.myFunc); But nothing seem to happen at all. 回答1: If you're triggering an event on v1 with: this.trigger('myEvent'); //

How To Find Triggered Event From Backbone.listenTo?

帅比萌擦擦* 提交于 2019-12-07 04:03:08
问题 In Backbone, I'm using the new Backbone.listenTo event. One of my instances has the listener attached to three different events e.g.: this.listenTo(this._Collection, 'reset add change', this._setCollection); It is called appropriately when it's supposed to and there are no issues there. What I don't know is how to find out which event was triggered. I have access to the e argument using: _setCollection: function(e) { // Do fun stuff } The problem is that the e argument only sends a copy of

Typescript Backbone View Events do not fire

孤街醉人 提交于 2019-12-06 15:01:31
I'm trying to make a simple view to test with backbone. I've started with events, but no one fires. Why ? I've made already other things with backbone like routing etc. without problems. Thanks for your time. My backbone definitions are from -> this source <- module Views { export class MenuView extends Backbone.View { constructor(viewOptions?: Backbone.ViewOptions) { super(viewOptions); } el = document.body; events = { "click #Btn-Start": "navigate", "click #Btn-Software": "navigate", "click #Btn-Anderes": "navigate", "click #Btn-Impressum": "navigate" }; initialize() { console.log(

Event handling between views

匆匆过客 提交于 2019-12-06 06:29:46
问题 Ok I have a layout like the one in this pic: The table in the upper part of the screen is made by: MessageListView define(['backbone','collections/messages','views/message'], function(Backbone, MessageCollection, MessageView) { var MessageListView = Backbone.View.extend({ el: '#messagesContainer', initialize: function() { this.collection = new MessageCollection(); this.collection.fetch({reset:true}); this.listenTo( this.collection, 'reset', this.render ); this.table = this.$el.find("table

Backbone events on model firing on collection (Double firing)

不打扰是莪最后的温柔 提交于 2019-12-06 02:09:34
问题 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,

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

时光总嘲笑我的痴心妄想 提交于 2019-12-05 10:45:29
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).html(this.template()); }, activateWidgets: function(){ if(!(this.widgets_view)){ this.widgets_view = new

How To Find Triggered Event From Backbone.listenTo?

我与影子孤独终老i 提交于 2019-12-05 08:41:25
In Backbone, I'm using the new Backbone.listenTo event. One of my instances has the listener attached to three different events e.g.: this.listenTo(this._Collection, 'reset add change', this._setCollection); It is called appropriately when it's supposed to and there are no issues there. What I don't know is how to find out which event was triggered. I have access to the e argument using: _setCollection: function(e) { // Do fun stuff } The problem is that the e argument only sends a copy of the collection and doesn't mention what event is actually triggered. I've tried e.type and e.target but

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

自古美人都是妖i 提交于 2019-12-05 02:15:21
问题 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

How to know when a Backbone model.fetch() completes?

坚强是说给别人听的谎言 提交于 2019-12-05 01:03:40
I bind on the change event of my backbone models like this. this.model.on( "change", this.render, this ); Sometimes I want to fetch the latest version of the model and forcibly render the view. So I do this this.model.fetch(); Unfortunately model.fetch() only fires the change event if the new data is different from what was previously stored in the model. How can I always trigger a this.render callback when fetch completes, whether it triggers a change event or not? Thanks (in advance) for your help You can use the $.ajax success callback, but you can also just listen for the Backbone sync and