【问题标题】:marionette todomvc extend error木偶 todomvc 扩展错误
【发布时间】:2013-01-26 03:36:17
【问题描述】:
TodoMVC.module "TodoList", (TodoList, App, Backbone, Marionette, $, _) ->

  # TodoList Router
  # ---------------
  #
  # Handle routes to show the active vs complete todo items
  TodoList.Router = Marionette.AppRouter.extend
    appRoutes: "*filter": "filterItems"

  # TodoList Controller (Mediator)
  # ------------------------------
  #
  # Control the workflow and logic that exists at the application
  # level, above the implementation detail of views and models
  TodoList.Controller = ->
    @todoList = new App.Todos.TodoList()

  _.extend TodoList.Controller::,

    # Start the app by showing the appropriate views
    # and fetching the list of todo items, if there are any
    start: ->
      @showHeader @todoList
      @showFooter @todoList
      @showTodoList @todoList
      App.bindTo @todoList, "reset add remove", @toggleFooter, this
      @todoList.fetch()

    showHeader: (todoList) ->
      header = new App.Layout.Header(collection: todoList)
      App.header.show header

    showFooter: (todoList) ->
      footer = new App.Layout.Footer(collection: todoList)
      App.footer.show footer

    showTodoList: (todoList) ->
      App.main.show new TodoList.Views.ListView(collection: todoList)

    toggleFooter: ->
      App.footer.$el.toggle @todoList.length

    # Set the filter to show complete or all items
    filterItems: (filter) ->
      App.vent.trigger "todoList:filter", filter.trim() or ""


  # TodoList Initializer
  # --------------------
  #
  # Get the TodoList up and running by initializing the mediator
  # when the the application is started, pulling in all of the
  # existing Todo items and displaying them.
  TodoList.addInitializer ->
    controller = new TodoList.Controller()
    new TodoList.Router(controller: controller)
    controller.start()

未捕获的 NoMethodError:在控制器上找不到方法“filterItems”

我采用了TodoMVC example for Marionette,并使用js2coffee 将其转换为CoffeeScript,我正在使用requirejs。我不确定为什么会这样,因为我没有添加真正的自定义代码。如果我可以提供任何其他信息,请告诉我。

【问题讨论】:

    标签: backbone.js coffeescript requirejs marionette todomvc


    【解决方案1】:

    我也遇到了这个错误。

    问题出在以下代码中:

    TodoList.Controller = ->
        @todoList = new App.Todos.TodoList()
    

    转换成 JS 后会在第二行前面加上return。对我来说,添加true 作为下一行解决了这个问题。

    TodoList.Controller = ->
        @todoList = new App.Todos.TodoList()
        true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多