backbone-events

Can't get Backbone routes without hashes?

…衆ロ難τιáo~ 提交于 2019-11-29 10:10:13
问题 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

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

回眸只為那壹抹淺笑 提交于 2019-11-28 15:22:02
问题 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() { this.model.selected = !this.model.selected; if(this.model.selected) $(this.el).addClass('selected'); else $(this.el).removeClass('selected'); return this; } }); var AppView = Backbone.View.extend({ ...some code... delete_selected: function() { _.each(Brands.selected(), function

Bubbling events in nested Backbone (Marionette) Models / Collections

爱⌒轻易说出口 提交于 2019-11-28 02:19:59
We have a large Marionette App, that uses Backbone.trackit to monitor unsaved changes in our Models. We now have some nested models, in fact we have a Model, with a Collection of Models, that contain a Collection of Models. trackit doesn't support the top level model being marked as 'dirty' when the child models change - due to backbone not bubbling these change events. I know we could manually monitor these change events, but Im looking for a generic solution. Has anyone had any experience of the following libs or any other solutions for this? backbone-deep-model Backbone Associations events

Listen to changes from nested model attributes

笑着哭i 提交于 2019-11-27 09:50:01
I have a model attribute which is an object: name : "testing", orderCondition: { minOrderAmount: 20, deliveryCostRequire: "MIN_ORDER_AMOUNT", deliveryCostAmount: 5.55 } When I use listenTo like this, the render function is not called this.listenTo(this.model, "change:orderCondition", this.render); // NO FIRING But when I use listenTo on other attributes, it works. this.listenTo(this.model, "change:name", this.render); // FIRING Why listenTo doesn't see changes in nested objects but see them in simple attributes? A simple way to make the nested object attribute trigger a change event is to

Backbone click event not firing in template View

会有一股神秘感。 提交于 2019-11-27 08:50:28
问题 I am working on a Backbone application which is based on a dynamic template . I have a header view, a side panel view and footer view that are dynamically initialized when calling any other view . The problem is I have events on each template view that are not firing. For example i have a button that changes the language in the header view but its event isn't firing. My header View : define([ "jquery", "backbone", "text!../../pages/header.html" ], function($, Backbone, headerTpl) { var header

Backbone View: Inherit and extend events from parent

戏子无情 提交于 2019-11-27 05:51:20
Backbone's documentation states: The events property may also be defined as a function that returns an events hash, to make it easier to programmatically define your events, as well as inherit them from parent views. How do you inherit a parent's view events and extend them? Parent View var ParentView = Backbone.View.extend({ events: { 'click': 'onclick' } }); Child View var ChildView = ParentView.extend({ events: function(){ ???? } }); One way is: var ChildView = ParentView.extend({ events: function(){ return _.extend({},ParentView.prototype.events,{ 'click' : 'onclickChild' }); } }); Another

Backbone 0.9.9: Difference between listenTo and on

风流意气都作罢 提交于 2019-11-27 02:50:36
I am trying to learn the new changes they did in Backbone 0.9.9. Currently I got problems to understand the difference between listenTo and on : listenTo var View = Backbone.View.extend({ tagName: "div", intialize: function() { this.listenTo(this.model, 'change', this.render); }, render: function() { this.$el.empty(); this.$el.append('<p>hello world</p>'); } }); on var View = Backbone.View.extend({ tagName: "div", intialize: function() { this.model.on('change', this.render, this); }, render: function() { this.$el.empty(); this.$el.append('<p>hello world</p>'); } }); I have heard that listenTo

Backbone: event lost in re-render

时光毁灭记忆、已成空白 提交于 2019-11-27 00:20:33
I have super-View who is in charge of rendering sub-Views . When I re-render the super-View all the events in the sub-Views are lost. This is an example: var SubView = Backbone.View.extend({ events: { "click": "click" }, click: function(){ console.log( "click!" ); }, render: function(){ this.$el.html( "click me" ); return this; } }); var Composer = Backbone.View.extend({ initialize: function(){ this.subView = new SubView(); }, render: function(){ this.$el.html( this.subView.render().el ); } }); var composer = new Composer({el: $('#composer')}); composer.render(); When I click in the click me

Bubbling events in nested Backbone (Marionette) Models / Collections

只谈情不闲聊 提交于 2019-11-26 23:39:59
问题 We have a large Marionette App, that uses Backbone.trackit to monitor unsaved changes in our Models. We now have some nested models, in fact we have a Model, with a Collection of Models, that contain a Collection of Models. trackit doesn't support the top level model being marked as 'dirty' when the child models change - due to backbone not bubbling these change events. I know we could manually monitor these change events, but Im looking for a generic solution. Has anyone had any experience

Listen to changes from nested model attributes

可紊 提交于 2019-11-26 14:52:43
问题 I have a model attribute which is an object: name : "testing", orderCondition: { minOrderAmount: 20, deliveryCostRequire: "MIN_ORDER_AMOUNT", deliveryCostAmount: 5.55 } When I use listenTo like this, the render function is not called this.listenTo(this.model, "change:orderCondition", this.render); // NO FIRING But when I use listenTo on other attributes, it works. this.listenTo(this.model, "change:name", this.render); // FIRING Why listenTo doesn't see changes in nested objects but see them