backbone-routing

how to switch views with the backbone.js router?

五迷三道 提交于 2019-12-02 00:39:23
问题 This is more of a conceptual question, in terms of using the backbone router and rendering views in backbone. for the sake of an example (what I'm building to learn this with) I've got a basic CRUD app for contacts, with create form, a listing of all contacts, a contact single view and an edit form. for simplicities sake I'm going to say that I would only want to see one of these things at a time. Obviously showing and hiding them with jQuery would be trivial, but thats not what I'm after. I

how to switch views with the backbone.js router?

房东的猫 提交于 2019-12-01 22:49:46
This is more of a conceptual question, in terms of using the backbone router and rendering views in backbone. for the sake of an example (what I'm building to learn this with) I've got a basic CRUD app for contacts, with create form, a listing of all contacts, a contact single view and an edit form. for simplicities sake I'm going to say that I would only want to see one of these things at a time. Obviously showing and hiding them with jQuery would be trivial, but thats not what I'm after. I have two ideas, 1) trigger custom events from my router that removes all views and sends events that

Backbone.js Router initialization doesn't run immediately

不打扰是莪最后的温柔 提交于 2019-12-01 21:21:05
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._todos}); //self._index.render(); } }); return this; } return this; }, index: function(){ this._index

Get previous router/url in backbone application

社会主义新天地 提交于 2019-11-30 23:10:35
问题 I have a backbone application and i would require to know the router from which the current route is accessed. Is it possible? For eg :- I reach #/current from #/test1 and also in another instance, from #/test1 . So can i know through some way to detect the previous router hit? Ive used : Backbone.history.fragment and this only gives me the current route accessed and not from which route. 回答1: You can store your history in some array and do some manipulation with last/previous items. var

How to trigger the Backbone.Router events in Backbone.js?

倖福魔咒の 提交于 2019-11-30 03:54:36
Router in Backbone.js is responsible for routing client-side pages, and connecting them to actions and events based on urls. But how to trigger the url change? I mean if the only way to do this is to enclose the element associated with page routing in <a> tag. Because I have associated the mousedown and mouseup events with the element used for routing, if I put it in <a> tag, the mousedown and mouseup events will definitely become invalid as it will have conflict with the click event of <a> tag. So is there other ways to make the routing? You can use Router#navigate : navigate router.navigate

How to trigger the Backbone.Router events in Backbone.js?

折月煮酒 提交于 2019-11-29 01:26:01
问题 Router in Backbone.js is responsible for routing client-side pages, and connecting them to actions and events based on urls. But how to trigger the url change? I mean if the only way to do this is to enclose the element associated with page routing in <a> tag. Because I have associated the mousedown and mouseup events with the element used for routing, if I put it in <a> tag, the mousedown and mouseup events will definitely become invalid as it will have conflict with the click event of <a>

navigate route with querystring

主宰稳场 提交于 2019-11-28 04:30:36
Will Backbone.Router.navigate set test to true : var test = false; var Router = Backbone.Router.extend({ routes: { 'posts': 'showPosts' }, showPosts: function () { test = true; } }); router = new Router(); Backbone.history.start(); router.navigate('posts?foo=3', {trigger: true}); assert.ok(test); Eg, will posts?foo=3 fragment will match the posts route by default, or do I have to set another route for that, for example: posts?*querystring ? Thank you PS: I know there exist the backbone-query-parameters but I want to know just for backbone. You need to add another route with that expecting

navigate route with querystring

人盡茶涼 提交于 2019-11-27 00:21:17
问题 Will Backbone.Router.navigate set test to true : var test = false; var Router = Backbone.Router.extend({ routes: { 'posts': 'showPosts' }, showPosts: function () { test = true; } }); router = new Router(); Backbone.history.start(); router.navigate('posts?foo=3', {trigger: true}); assert.ok(test); Eg, will posts?foo=3 fragment will match the posts route by default, or do I have to set another route for that, for example: posts?*querystring ? Thank you PS: I know there exist the backbone-query