backbone-events

How to get a correct event target in Backbone.js View that is listen to an event of jqGrid?

谁都会走 提交于 2019-12-13 04:27:26
问题 I use jqGrid together with Backbone.js and I have the view that represents the grid. The code is below: var GridView = Backbone.View.extend({ initialize: function(){ _.bindAll(this); }, beforeSelectRow:function(e){ return $(e.target).is('img') ? false : true; }, render: function(){ var self = this; this.$el.load( this.collection.url + 'grid/', function(){ self.$jqGrid = self.$('.jqGrid'); self.$jqGrid.on('jqGridBeforeSelectRow',self.beforeSelectRow); } ); return this; } }); The grid's row can

The best way to fetch and render a collection for a given object_id

元气小坏坏 提交于 2019-12-13 02:23:15
问题 I am trying to implement a simple app which is able to get a collection for a given object_id . The GET response from the server looks like this: [ {object_id: 1, text: "msg1"}, {object_id: 1, text: "msg2"}, {object_id: 1, text: "msg3"}, ....... ] My goal is: render a collection when the user choose an object_id . The starting point of my code is the following: this.options = {object_id: 1}; myView = new NeView(_.extend( {el:this.$("#myView")} , this.options)); My question is: * What is the

How receive link attributes of event in Backbone?

陌路散爱 提交于 2019-12-13 00:45:47
问题 I want to receive attributes in Backbone View of this link. I'm not sure this is right way to do this in Backbone. Maybe params of this link should be set on view rendering? <a class="postDeleteLink" data-id="5" data-hash="Hgsda45f">Delete</a> My Backbone code to bind an event: PostListView = Backbone.View.extend({ events: { "click .postDeleteLink": "deletePost" }, deletePost: function(){ //standart jquery way doesn't work, because "this" is already used by backbone var id = $(this).attr(

Backbone View not refreshing even when Collection gets Refreshed

一曲冷凌霜 提交于 2019-12-12 04:56:37
问题 I have a backbone collection that dynamically takes the URL to fetch results. I then create a view that has the key-up event to capture key input and refresh the collection from the back-end. I have added a listener to my view for collection change but that is not being triggered on my key-up event even though the collection is getting refreshed. employees.EmployeesCollection = Backbone.Collection.extend({ url: function() { if(this.searchName) return serviceUrls.employees_searchByName_url + "

fire event written in child view in backbone.js

血红的双手。 提交于 2019-12-12 02:55:11
问题 I am using backbone js. suppose i have a child view called 'childView' and a parent view called 'parentView'. parentView = Backbone.View.extend({ render: function () { new childView().render(); } }) childView = Backbone.View.extend({ render: function () { }, events: { 'click .abc' : 'fireEvent' } }) I need to call click event written in childView in a parentView. 回答1: The simplest way is to use Backbone.View 's instance. Backbone.View is mixed with Backbone.Events which give you possibility

How to handle a simple click event in Backbone.js?

耗尽温柔 提交于 2019-12-12 01:23:13
问题 I am having difficulty with something very simple in Backbone. I want to wire up the <h1> in my page so that when the user clicks on it, it returns seamlessly to the homepage, without a postback. This is the HTML: <h1><a id="home" href="/">Home</a></h1> (UPDATE: fixed ID as suggested by commenter.) And this is my Backbone view and router: var HomeView = Backbone.View.extend({ initialize: function() { console.log('initializing HomeView'); }, events: { "click a#home": "goHome" }, goHome:

How to design a controller in Backbone.js?

你说的曾经没有我的故事 提交于 2019-12-11 02:22:29
问题 I am interested in having a controller to coordinate rendering, event processing, URL router navigation and network access. A bit similar to what a Controller does in Spine: http://spinejs.com/docs/controllers In the realm of Backbone, what I could find so far is an article by Derick Bailey: http://lostechies.com/derickbailey/2011/08/28/dont-execute-a-backbone-js-route-handler-from-your-code/ In Derick's code however, the Controller seems not to be used anymore within the Routes. Also, I was

window resize event for backbone view

我的未来我决定 提交于 2019-12-10 21:29:58
问题 I am using Backbone view in javascript. I have created a backbone view as follows : var MaskView = Backbone.View.extend({ className: "dropdown-mask", initialize: function(){ }, onClick: function(e){ }, hide: function(){ }, makeCSS: function(){ return { width : Math.max(document.documentElement.scrollWidth, $(window).width()), height : Math.max(document.documentElement.scrollHeight, $(window).height()) } } }); i want to capture event of window resizing inside the view. The problem is that,

Backbone.js html select / radio change event is not firing, but click event is

假装没事ソ 提交于 2019-12-10 20:58:39
问题 I am learning backbone but I'm stuck at binding a onchange event for html option element. I tried to bind with 'change' or 'change #id' but none of these fire. However, both the 'click' and 'click #id' event work. <div id='target'> <select id='abc'> <option value=1>1</option> <option value=2>2</option> </select> </div> <input type='radio' name='def' value='1' checked>1</input> <input type='radio' name='def' value='2'>2</input> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1

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

隐身守侯 提交于 2019-12-10 01:50:20
问题 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