0

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
3
  • What calls listUsers and why do you expect @ to be anything in particular when it that function is called? Commented Jul 21, 2014 at 17:02
  • Sure - I added my code above. Probably worth noting I tried removing the this or @ from layout, but it does the same thing. I'm actually following Brian Mann's tutorial at backbonerails.com which states it is needed later in the controller. Commented Jul 21, 2014 at 17:20
  • To your question though - 'listUsers' is called when the user navigates to the localhost:3000/users url (or they are routed there after going to the localhost:3000 url as well via the last function in app.js.coffee) Commented Jul 21, 2014 at 17:21

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.