我正在尝试在 Spine.js 中设置嵌套堆栈。
尽管我复制粘贴了似乎对其他人有用的代码(https://gist.github.com/MikeSilvis/2839845)并调整了控制器和型号名称,但它不起作用。 两个堆栈都显示得非常正确,控制台中也没有错误。但是 - 如果我没有完全误解嵌套堆栈的用法 - 它们不会嵌套在根堆栈中。有什么我必须在视图中添加的吗?
index.coffee:
class App extends Spine.Controller
constructor: ->
super
new Spine.SubStack
Spine.Route.setup()
@append(@groups = new App.Groups)
@append(@people = new App.People)
class App.Root extends Spine.Stack
$.fn.item = ->
elementID = $(@).data('id')
elementID or= $(@).parents('[data-id]').data('id')
Person.find(elementID)
controllers:
groups: App.Groups
people: App.People
routes:
'/groups' : 'groups'
'/people' : 'people'
default: 'people'
className: 'stack root'
class Spine.SubStack extends Spine.Stack
constructor: ->
for key,value of @routes
console.log [key, value].join(" | ")
do (key,value) =>
@routes[key] = =>
@active()
@[value].active(arguments...)
super
window.App = App
在 groups.coffee 中:
class App.Groups extends Spine.SubStack
controllers:
index: Index
edit: Edit
show: Show
new: New
routes:
'/groups/new': 'new'
'/groups/:id/edit': 'edit'
'/groups/:id': 'show'
'/groups': 'index'
default: 'index'
className: 'stack groups'
在 people.coffee 中:
class App.People extends Spine.SubStack
controllers:
index: Index
edit: Edit
show: Show
new: New
routes:
'/people/new': 'new'
'/people/:id/edit': 'edit'
'/people/:id': 'show'
'/people': 'index'
default: 'index'
className: 'stack people'
添加此代码后,所有路由仍然有效,但没有根堆栈。
希望比我有更多经验的人可以帮助我解决这个问题!