Backbone的任何实例都不起作用,我的控制台说这是未定义的......
截至目前,它说: 未捕获的TypeError:无法调用未定义的方法'start'
与此相关:
Backbone.history.start()
这是我的app.js代码:
app =
facebookAuth()
class manageView extends Backbone.View
constructor: ->
super
initialize: ->
template: _.template($('#manage').html())
render: ->
$('#page').append(@template())
class AppRouter extends Backbone.Router
routes:
"": "manage"
initialize: ->
manage: ->
new manageView()
$(document).ready( ->
console.log('document ready')
app.AppRouter = new AppRouter()
Backbone.history.start()
)
这就是我如何包含我的js文件(它们都指向正确的路径):
<script type="text/javascript" charset="utf-8" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/underscore-min.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/backbone-min.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/less-1.3.0.min.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/facebook-auth.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
谁能告诉我为什么?谢谢!
答案 0 :(得分:2)
当时可能没有创建路由器。尝试下一步:
class AppRouter extends Backbone.Router
routes:
"": "manage"
initialize: ->
Backbone.history.start()
manage: ->
new manageView()
$(document).ready( ->
console.log('document ready')
app.AppRouter = new AppRouter()
)