Comments (3)
You should be able access it with:
this.locale
Here's a functional example in CoffeeScript - different syntax, same principle:
App.Routers.Shop = Backbone.SubRoute.extend
initialize: (options) ->
@locale = options.locale
routes:
'books(/*subroute)' : 'books'
books: ->
new App.Routers.Shop.Books("#{ @prefix }/books", { locale: @locale, createTrailingSlashRoutes: true })
from backbone.subroute.
Hi @aeksco, sorry I got carried away and forgot critical details that I'm both using marionette and Marionette.Subrouter https://github.com/pushchris/backbone.marionette.subrouter ... which both are supposed to be extensions but anyways, I understand why this works in your example and also see now why it doesn't work in mine (below) but I still would love to find a solution.
Backbone.Router > Marionne.AppRouter > Marionette.SubRouter
Marionette Router derived from Backbone Router and Marionette SubRouter derives from AppRouter but clearly there's a ton of more things happening.
In my case using appRoutes this
from inside my callback just gives me back the actual controller passed to the router or in this case below API
which is an object with keys representing the functions
API =
myPath: ->
# debugger # how can I access options here
class MyApp.Router extends Marionette.SubRouter
controller: API
initialize: (options) ->
{ @myvar } = options
appRoutes:
"my-path" : "myPath"
I guess this is a Marionette question
from backbone.subroute.
Interesting - wasn't familiar with Marionette.Subrouter. Learning new things everyday :D
Superficially the issue you're experiencing appears to be a result of your method not being properly bound to the subrouter instance.
For example, you have:
myCallback: function() {
console.log(this.foo);
}
Where you really need:
myCallback: (function(_this) {
return function() {
console.log(_this.foo);
};
})(this)
If I'm not mistaken, the above is typically going to be used when the method you're defining is a callback that references instance fields in the parent object.
The distinction in CoffeeScript is terse and fails to clarify the underlying principles, though researching the nuances between thin arrows and fat arrows will shed some light on your dilemma, given of course that the rest of the code is functioning well.
myCallback: ->
console.log @foo
VS
myBoundCallback: =>
console.log @foo
Hope this helps - good luck!
from backbone.subroute.
Related Issues (20)
- Routes with named params HOT 6
- How can I restart subroutes? HOT 2
- Suggestion: returning Backbone.navigate or at least returning "this" HOT 3
- Polluted Routes when using a common base router class HOT 5
- Problem with Backbone AMD HOT 3
- Minified version produces wrong route HOT 1
- Filter support HOT 5
- Publish latest version to npm HOT 1
- Backbone and underscore should be dependencies (not devDependencies) HOT 1
- Route gets triggered twice HOT 3
- using back button does not re-trigger all my routes
- loadUrl into uninitialized subroute fails HOT 3
- Seeking New Ownership! HOT 6
- Specify createTrailingSlashRoutes as an instance property when extending from Backbone.Subroute
- handling zombie views in the subroute
- Update bower info
- npm support
- Regex routes
- Multiple SubRoutes - is it possible?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone.subroute.