【问题标题】:Spine.js - How to set up nested stacksSpine.js - 如何设置嵌套堆栈
【发布时间】:2013-06-03 15:11:42
【问题描述】:

我正在尝试在 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'

添加此代码后所有路由仍然有效,但没有根堆栈。

希望经验比我多一点的人可以帮助我解决这个问题!

【问题讨论】:

    标签: spine.js


    【解决方案1】:

    无需进行太多研究,您似乎应该在某处拥有new App.Rootextends App.Root。这可以解释为什么您的路线有效,但没有根堆栈。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2019-03-09
      • 2015-04-07
      • 2019-07-12
      • 2017-11-25
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多