【发布时间】:2012-01-24 01:14:22
【问题描述】:
我将spine.js 与Spine.Ajax 模块结合使用,通过JSON 从服务器加载内容。我可能遇到了一些同步问题。我有一个侧边栏,它只绑定到刷新和更改事件,然后被渲染:
Survey.bind 'refresh change', @render
我还设置了一些路由,当用户通过#/survey/:id 访问它时会显示一个调查。这是我的控制器:
class App.Surveys extends Spine.Controller
className: 'surveys'
constructor: ->
super
@append(@sidebar = new App.Sidebar) # Sidebar to select surveys
@append(@surveys = new App.SurveysStack) # Show survey details survey
@routes
'/surveys/:id': (params) ->
@sidebar.active(params)
@surveys.show.active(params)
Survey.fetch()
如您所见,Survey.fetch() 在初始化之后被调用,这不会对侧边栏造成问题。但是,它似乎给调查Show 控制器(由称为App.SurveyStack 的Spine.Stack 调用)带来了问题:
class Show extends Spine.Controller
constructor: ->
super
@active @change
change: (params) =>
# There is a bug! If Survey is not fetched when we run this,
# this throws an error.
@item = Survey.find(params.id)
@render()
render: ->
@html @view("surveys/show")(@item)
我不断收到来自源注释部分的错误:Uncaught Unknown record。我可以在完成Survey.fetch() 之前制作Survey.find() 功能块吗?
【问题讨论】:
标签: ajax coffeescript spine.js