backbone-views

Is using the same id multiple times on a page bad practice even when I am not parsing through the page?

大兔子大兔子 提交于 2019-12-01 16:13:48
I understand that using the same id multiple times in a page creates malformed html. When using a jquery selector only the first element with the id will be returned, but in my application I shouldn't be running into this issue. I have list of items views that will all have an element I need to refer to. Since each item only has access to its own $el passing in an id selector for something will not produce any conflicts (even if there are multiple on the page). I've simulated what I mean in a fiddle here In this project I am not doing any page wide parses so I believe it should be safe. Is

Is using the same id multiple times on a page bad practice even when I am not parsing through the page?

人走茶凉 提交于 2019-12-01 15:19:10
问题 I understand that using the same id multiple times in a page creates malformed html. When using a jquery selector only the first element with the id will be returned, but in my application I shouldn't be running into this issue. I have list of items views that will all have an element I need to refer to. Since each item only has access to its own $el passing in an id selector for something will not produce any conflicts (even if there are multiple on the page). I've simulated what I mean in a

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 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

What is the difference between $el and el in Backbone.js views?

假装没事ソ 提交于 2019-11-29 19:48:56
Can you please tell the difference between $el and el in Backbone.js views? Rayweb_on lets say that you do this var myel = this.el; // here what you have is the html element, //you will be able to access(read/modify) the html //properties of this element, with this var my$el = this.$el; // you will have the element but //with all of the functions that jQuery provides like, //hide,show etc, its the equivalent of $('#myel').show(); //$('#myel').hide(); so this.$el keeps a reference to your //element so you don't need to traverse the DOM to find the // element every time you use it. with the

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

Backbone.js - change not triggering while the name change

爷,独闯天下 提交于 2019-11-27 09:54:25
In my backbone function, while the name get change the change function not at all triggering.. any one suggest me the right way to get it.. (actually i need to get changed stuff and need to update); code : (function($){ var list = {}; list.model = Backbone.Model.extend({ defaults:{ name:'need the name' }, initialize:function(){ this.bind('change:name', function(model) { console.log('Model->change()', model); }); } }); list.collect = Backbone.Collection.extend({ model:list.model, url : 'data/names.json', initialize:function(){ this.fetch({update:true}); this.keepUpdate(); }, keepUpdate:function

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