我想配置路由器與Backbone.js和接收異常在行1414 Backbone.js的的Safari瀏覽器和Chrome存在1.1.2
錯誤:
[Error] TypeError: 'undefined' is not a function (evaluating 'Backbone.$(window).on('hashchange', this.checkUrl)')
start (backbone.js, line 1414)
(anonymous function) (index.html, line 27)
這裏的index.html文件,第27行是Backbone.History.start()
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<head>
<link rel="stylesheet" href="bootstrap.min.css">
</head>
<body>
<div class="container">
</div>
<script src="../jquery.js"></script>
<script src="../underscore.js"></script>
<script src="../backbone.js"></script>
<script src="../json2.js"></script>
</body>
<!-- BACKBONE -->
<script type="text/javascript">
(function($) {
var PageRouter = Backbone.Router.extend({
routes: {
'': 'index'
}
});
var pageRouter = new PageRouter();
pageRouter.on('index', function() {
console.log('hey');
});
Backbone.history.start();
})(jQuery)
</script>
</html>
我找不到很多資源來幫忙,並且大部分的公關現有的資源強調了路由器的分配,並且我感覺它的實現是正確的。此外,我不認爲有必要有一個集合或模型,因爲我只是試圖在這個時候實現路由。任何幫助將不勝感激,謝謝。
**編輯**
我重新排序腳本進口:
<script src="../underscore.js"></script>
<script src="../backbone.js"></script>
<script src="../jquery.js"></script>
<script src="../json2.js"></script>
,改變了錯誤TypeError: 'undefined' is not a function (evaluating 'Backbone.$(window)')
添加斷點Backbone.js的行1414指示錯誤來自評估this.checkUrl
checkUrl: function() { [native code] } arguments: (...) get arguments: function ThrowTypeError() { [native code] } set arguments: function ThrowTypeError() { [native code] } caller: (...) get caller: function ThrowTypeError() { [native code] } set caller: function ThrowTypeError() { [native code] } length: 1 name: "" __proto__: function Empty() {} [[TargetFunction]]: function (e) { [[BoundThis]]: Backbone.History [[BoundArgs]]: Array[0]
根據多個來源,我設置路由器的方式實際上是事實上的,不管(function($){})(jQuery)
是什麼,也不知道如何獲得正確分配的路徑。使用#
沒有幫助我。
怎麼樣在該代碼中放置一個斷點? –
backbone.js顯示:本地{docMode:undefined,fragment:「」,frame:undefined,loc:undefined,oldIE:null,options:undefined,this:Backbone。歷史{_hasPushState:false,_wantsHashChange:true,_wantsPushState:false}} – aug2uag
嘗試傳遞選項{pushState:true},並在'extend'中定義'index:function(){}',所有上述結果都帶有'Uncaught TypeError:未定義是不是一個函數',並找不到解決方案從以前的帖子http://stackoverflow.com/questions/7343357/cannot-call-start-of-undefined-when-starting-backbone-js-history – aug2uag