简体   繁体   中英

Coffeescript Uncaught TypeError: object is not a function Error

Any idea why the @layout = @getLayoutView() line is throwing a Uncaught TypeError: object is not a function error? I can't seem to figure it out. As always any help is very much appreciated!

list_controller.js.coffee:

@Demo.module "UsersApp.List", (List, App, Backbone, Marionette, $, _) ->

    List.Controller =

      listUsers: ->
        users = App.request "user:entities"
        @layout = @getLayoutView()
        App.mainRegion.show @layout

      getLayoutView: ->
        new List.Layout

list_view.js.coffee:

@Demo.module "UsersApp.List", (List, App, Backbone, Marionette, $, _) ->

  List.Layout = new Marionette.LayoutView
    template: "users/list/templates/list_layout"

EDIT Adding Routing Logic

user_app.js.coffee:

@Demo.module "UsersApp", (UsersApp, App, Backbone, Marionette, $, _) ->

    class UsersApp.Router extends Marionette.AppRouter
        appRoutes:
            "users": "listUsers"

    API =
        listUsers: ->
            UsersApp.List.Controller.listUsers()

    App.addInitializer ->
        new UsersApp.Router
            controller: API

app.js.coffee:

@Demo = do (Backbone, Marionette) ->

  App = new Marionette.Application

  App.rootRoute = "users"

  App.addRegions
    headerRegion: "#header-region"
    mainRegion: "#main-region"
    footerRegion: "#footer-region"

  App.addInitializer ->
    App.module("HeaderApp").start()
    App.module("FooterApp").start()

  App.on "start", ->
    if Backbone.history
      Backbone.history.start()
      @navigate(@rootRoute, trigger: true) if @getCurrentRoute() is ""

  App

I guess you supposed to extend List.Layout from 'Marionette.LayoutView', but the code snippet here creating a instance of 'Marionette.LayoutView'. The code

List.Layout = new Marionette.LayoutView
    template: "users/list/templates/list_layout"

should have been

class List.Layout extends  Marionette.LayoutView
   template: "users/list/templates/list_layout"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM