我正在开发一个 Backbone Marionette 网络应用程序。在这个应用程序中,我得到了如下所示的路线:
projects/:id/tasks
如何获取该路由的 ID (URL)?
如果我使用它,我会得到整个 URL:
Backbone.history.fragment
更新
这就是我为项目定义路线的方式。
@Projectapp.module "ProjectsApp", (ProjectsApp, App, Backbone, Marionette, $, _) ->
class ProjectsApp.Router extends Marionette.AppRouter
appRoutes:
"projects/new" : "newProject"
"projects/:id" : "showProject"
"projects/:id/edit" : "editProject"
"projects" : "listProjects"
API =
listProjects: ->
new ProjectsApp.List.Controller
newProject: ->
new ProjectsApp.New.Controller
showProject: (id, project) ->
new ProjectsApp.Show.Controller
id: id
project: project
editProject: (id, project) ->
new ProjectsApp.Edit.Controller
id: id
project: project
App.Router.on "route:newProject", (project_id) ->
alert project_id
App.commands.setHandler "new:crew:member", (region) ->
API.newCrew region
App.vent.on "project:new:clicked", (project) ->
App.navigate "projects/new", true
App.vent.on "project:tasks:clicked", (project) ->
App.navigate "projects/#{project.id}/tasks", true
App.vent.on "project:created", (project) ->
App.navigate "projects/#{project.id}", true
App.vent.on "project:show:clicked project:back:clicked", (project) ->
App.navigate "projects/#{project.id}"
API.showProject project.id, project
App.vent.on "project:clicked project:edit:clicked", (project) ->
App.navigate "projects/#{project.id}/edit"
API.editProject project.id, project
App.vent.on "project:cancelled project:list:back:clicked", (project) ->
App.navigate "projects"
API.listProjects()
App.addInitializer ->
new ProjectsApp.Router
controller: API