我正在尝试在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
in 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'
in 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'
添加此代码后,所有路由仍在工作,但没有根堆栈。
希望有一个比我更有经验的人能帮我解决这个问题!
发布于 2013-11-23 18:16:50
没有做太多的研究,你似乎应该在某个地方拥有一个new App.Root
或extends App.Root
。这可以解释为什么您的路由工作,但没有根堆栈。
https://stackoverflow.com/questions/16981940
复制相似问题