backbone-routing

backbone.js: accessing a property on deeplinked page

孤街醉人 提交于 2020-01-16 11:22:12
问题 I am working on an example using a router to switch to a new view. In this example the view's render function is using a console.log to successfully outputs the attributes, including the id, but the template does not display the id. I have tried to only put the relevant sections of the application here. var DetailView = Backbone.View.extend({ el: $('body'), template: _.template('this is detailview for <% id %><a href="index.htm">back</a>'), render: function(id){ var attributes = this.model

backbone.js: accessing a property on deeplinked page

元气小坏坏 提交于 2020-01-16 11:22:08
问题 I am working on an example using a router to switch to a new view. In this example the view's render function is using a console.log to successfully outputs the attributes, including the id, but the template does not display the id. I have tried to only put the relevant sections of the application here. var DetailView = Backbone.View.extend({ el: $('body'), template: _.template('this is detailview for <% id %><a href="index.htm">back</a>'), render: function(id){ var attributes = this.model

Backbone router not working on page load

与世无争的帅哥 提交于 2020-01-06 07:05:04
问题 I have a backbone application which works great, except for the routing on page load. I need to use the router to instantiate the correct view on page load, but for some reason the functions wont fire. Here is my code: var Router = Backbone.Router.extend({ routes: { ':page': 'pageAction', // Igonre this route - this fires successfully after an AJAX call 'our-approach.html': 'instantiateOurApproach', 'our-work.html': 'instantiateOurWork', 'who-we-are.html': 'instantiateWhoWeAre', 'social

BackboneJS + Codeigniter pushState true not working

假如想象 提交于 2019-12-25 16:55:29
问题 So I have this Backbone App where I use Codeigniter for the Backend. For some reason, pushState:true does not work. So, my main.js of my backbone app has this: Backbone.history.start({ pushState: true, root: App.ROOT }); My app.js has this: var App = { ROOT: '/projects/mdk/' }; and my navigation module, which renders the menulinks, each item has this: this.insertView(new ItemView({ model: new Navigation.ItemModel({ href: App.ROOT + 'home', class: 'home', triggers: 'home', route: this.route })

backbone.js routing when query passed to route contains /

走远了吗. 提交于 2019-12-23 09:57:41
问题 My app basically takes some form input and returns a set of results. I have two routes routes: { '': 'search', 'search': 'search', 'results/:query': 'results' }, results: function(query) { var search = new ResultsSearchView(); var grid = new GridView({ query: query }); } If the query contains any characters / specifically (can totally happen in this case), they are added to the URL and my route breaks. I have tried using encodeURI() and encodeURIComponent() bit I'm not having any luck. How

Bootstrap scrollspy and backbone routing

▼魔方 西西 提交于 2019-12-23 09:29:16
问题 How would i go about using Bootstrap's Scrollspy when I am using Backbone.js hash based routing? Backbone router example, which creates page www.example.com/#somePage/123 var AppRouter = Backbone.Router.extend({ routes: { "": "home", "somePage/:id": "somePage" }, somePage: function (id) { console.log("do something"); } }); $(document).ready(function(){ window.app = new AppRouter(); Backbone.history.start(); }); Twitter scrollSpy example which should append #anchor-value to the end the URL:

Backbone pushState and error 404

大城市里の小女人 提交于 2019-12-22 04:36:31
问题 I'm trying to implement the { pushState : true } but it works only for the base route, not with the other that continue to give me error 404. In Chrome, If I access: http://example.app/ - OK the console message is displayed http://example.app/show - error 404 is returned My route is var AppRouter = Backbone.Router.extend({ routes: { '': 'index', 'show': 'show' }, index: function() { console.log('This is the index page'); }, show: function() { console.log('This is the show page'); } }); new

Backbone router getting history length for back-button

二次信任 提交于 2019-12-22 00:33:19
问题 I'm using Backbone inside a PhoneGap application. Like every mobile app I need a back-button functionality. It's basically working perfectly with Backbone, because I can simply use window.history.back() and it just works. The only problem I have is to decide when to display the back button. Using window.history.length does not work, because it's not decremented when using back() (of course, because you can go forward() as well). Is there any way to detect if there's more history or if I'm

How to protect routes for different user groups

爱⌒轻易说出口 提交于 2019-12-20 06:02:50
问题 I'm building an app with backbone.js and wonder, how to protect routes for different user groups. I've seen many tutorials with some simple authentication methods, but i doesn't find any information about user groups. Let's say i have 2 user groups for my app: admins (read/write) and guests (read). How can i setup a secure authentication system with backbone.js, so that guests won't be able to open http://example.com/foo/1/edit? Any ideas? 回答1: One option is to only set-up the routes if the

Backbone.js Router initialization doesn't run immediately

∥☆過路亽.° 提交于 2019-12-20 02:07:25
问题 My code is as follows: var AppRouter = Backbone.Router.extend({ _data: null, _length: 0, _index: null, _todos: null, _subtodolist: null, _subtodos: null, routes: { "*action": "index", "category/:name": "hashcategory" }, initialize: function(options){ var self = this; if (this._index === null){ $.ajax({ url: 'data/todolist.json', dataType: 'json', data: {}, success: function(data) { self._data = data; self._todos = new TodosCollection(data); self._index = new CategoriesView({collection: self.