知道为什么 @layout = @getLayoutView()
行抛出 Uncaught TypeError: object is not a function
错误吗?我似乎无法弄清楚。一如既往,非常感谢任何帮助!
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.咖啡:
@Demo.module "UsersApp.List", (List, App, Backbone, Marionette, $, _) ->
List.Layout = new Marionette.LayoutView
template: "users/list/templates/list_layout"
编辑添加路由逻辑
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.咖啡:
@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
最佳答案
我猜你应该从“Marionette.LayoutView”扩展List.Layout,但这里的代码片段创建了“Marionette.LayoutView”的实例。代码
List.Layout = new Marionette.LayoutView
template: "users/list/templates/list_layout"
应该是
class List.Layout extends Marionette.LayoutView
template: "users/list/templates/list_layout"
关于javascript - Coffeescript 未捕获类型错误 : object is not a function Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24870261/