backbone-views

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

别说谁变了你拦得住时间么 提交于 2019-12-18 10:07:18
问题 Can you please tell the difference between $el and el in Backbone.js views? 回答1: 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

Backbone.js - change not triggering while the name change

浪子不回头ぞ 提交于 2019-12-13 10:27:49
问题 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

Add new collection to parent view from child view

孤者浪人 提交于 2019-12-13 07:20:52
问题 I have a parent view (which is for car engines) that contains a child view which displays a list of options. One of the options is to add a new collection to the parent view. My child view init function looks like this: initialize: function (engine) { this.engine = engine; //parent object this.valves = engine.valves; //may or may not be empty }; Then I have this method that adds the collection(valves) when a button is pressed: addPerformanceValves: function() { var self = this; if (this

Backbone not making a put request with save() after save

醉酒当歌 提交于 2019-12-13 05:24:28
问题 I am experiencing a really interesting problem with backbone, I have a function like this in one of my views: addpeople :function(){ var authArray = _.clone(this.model.get("authorizedUsers")); var values = $(".add-input").val().split(","); values.forEach(function(value) { authArray.push(value); }); this.model.set("authorizedUsers" , authArray); this.model.save(); }, this function gets called when a button is clicked. This version of the function triggers a change event because I am cloning my

Backbone Navigation Error

对着背影说爱祢 提交于 2019-12-13 04:31:28
问题 Whenever I press the back button in my browser the view is empty, and I get an error like this: I don't really know what part of my application I should put on here to help the problem but none of the errors refer to a part of my code.. Interestingly if I press the front button and press the back button again everything renders perfectly and the error is not there anymore. My router and views look like this: var AppRouter = Backbone.Router.extend({ initialize: function() { this.model = new

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 do I refresh/reload my DataTable from HTML source

五迷三道 提交于 2019-12-12 19:30:36
问题 I'm using BackboneJS to populate my table with multiple data sources . You do not need to know Backbone to assist in this question, as the issue is mainly a DataTables issue. I initialise my Datatable when the Collection View is rendered the first time. My issue is that I don't know how to tell DataTables how to reload its data from the DOM after each ajax request . Any idea on how to do this? Another example is when loading some data for each row and then updating it accordingly (done by

In backbone.js view, how do i call another function from jquery $.each?

旧时模样 提交于 2019-12-12 05:49:08
问题 In my backbone.js view i have a function that has the code below. I would usually call this function using this.addLayerToList() , but since it's in the $.each this. is not what I want. Can anyone help here? How would I call my function addLayerToList from the $.each ? initLayerList: function(){ $.each(baseLayers, function() { this.addLayerToList(this); }); }, addLayerToList : function() { //...some code here } 回答1: This should work. initLayerList: function(){ var that = this; $.each

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