2013-02-11 134 views
0
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擴展錯誤

我已經採取了TodoMVC example for Marionette上找到,並使用js2coffee它轉換爲CoffeeScript中,我使用requirejs。我不確定爲什麼會發生這種情況,因爲我沒有添加真正的自定義代碼。如果有任何其他信息可以包括,請告訴我。

回答

1

我也有這個錯誤。

的問題是在以下代碼:

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

它將在一次轉換爲JS第二線的前面添加return。對我而言,在下一行添加true解決了問題。

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