ajax - 脊柱.js: "Uncaught Unknown record"

标签 ajax coffeescript spine.js

我将spine.js 与Spine.Ajax 模块结合使用,通过JSON 从服务器加载内容。我可能遇到了一些同步问题。我有一个侧边栏,它仅绑定(bind)到刷新和更改事件,然后呈现:

Survey.bind 'refresh change', @render

我还设置了一些路线,当用户通过 #/survey/:id 访问它时,这些路线会显示调查。这是我的 Controller :

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 Controller (由名为 App.SurveyStackSpine.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)

我不断从源代码的注释部分收到错误:未捕获的未知记录。我可以阻止 Survey.find() 函数直到 Survey.fetch() 完成吗?

最佳答案

您的诊断是正确的,您在从服务器获取项目之前无法找到该项目。

最简单的解决方案是将事件绑定(bind)到 Survey.fetch() 调用,如下所示:

Survey.bind 'refresh change', @method_to_call

如果有帮助请告诉我!

关于ajax - 脊柱.js: "Uncaught Unknown record",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8980925/

相关文章:

javascript - 使用 Ajax 和 Python 返回 Highcharts

jquery - Google 会抓取 AJAX 内容吗?

javascript - 如何在asp.net MVC中使用href从javascript在新窗口中打开打开的窗口

javascript - jquery-datatables-rails 中忽略过滤器

build - 使用 Spine.js 和 Hem 时,有没有办法阻止它压缩 Javascript?

javascript - 如何将依赖项添加到我的 Spine 应用程序?

javascript - Ajax 以 dd/mm/yyyy 格式获取日期

javascript - Node.js:Server.js 的功能变得困惑

CoffeeScript 存在运算符和这个

javascript - 找不到未捕获的模块 jqueryify