Tôi đang thử nghiệm xung quanh với Backbone.js và tôi chỉ đơn giản là cố gắng để có được các tin nhắn bật lên trên màn hình giao diện điều khiển của tôi. Làm thế nào bao giờ, mỗi khi tôi làm như vậy một lỗi vẫn tiếp tục xuất hiện (lưu ý dưới đây)Uncaught TypeError: Mong đợi một chức năng trong instanceof kiểm tra
Uncaught TypeError: Expecting a function in instanceof check, but got [object Object] backbone.js:1032
_.extend.setElement backbone.js:1032
_.extend._ensureElement backbone.js:1104
Backbone.View backbone.js:986
child backbone.js:1531
(anonymous function) pageLoader.js:19
(anonymous function)
Dưới đây là tệp JavaScript
(function ($){
window.PageLoader = Backbone.View.extend({
el: $("section"),
events: {
"": "initialization",
"click #aboutUs" : "aboutUs",
},
initialization: function(){
console.log('pageLoader.js initialized\nHome page rendered');
},
aboutUs:function(){
console.log('About us page rendered.');
}
});
var pageLoader = new PageLoader();
//pageLoader.initialization();
//pageLoader.aboutUs();
})(jQuery);
Ngoài ra ở đây là HTML
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/main.css">
<meta />
<meta />
<title>Bus tours and tows</title>
</head>
<body>
<div id="centerWrapper">
<header>
<h1>So and so Bus tours and tows</h1>
<header/>
<nav>
<ul>
<li><a href="">Home</a></li>
<li><a href="#aboutUs">About us</a></li>
<li><a href="">Tours</a></li>
<li><a href="">Tows</a></li>
<li><a href="">Schedule</a></li>
<li><a href="">Contact</a></li>
</ul>
</nav>
<section></section>
<footer> © Of So and so bus tours and tows. <br />
<i>Questions regarding the construction of the website, please email</i>
<a href="mailto: [email protected]">Web Master</a>
</footer>
<div id="jsFilesAndDepend">
<!-- -->
<!-- Filese that are dependant-->
<script src="js/dependencies/underscore.js"></script>
<script src="js/dependencies/backbone.js"></script>
<script src="js/dependencies/jquery-1.10.1.js"></script>
<script src="js/pageLoader.js"></script>
<script src=""></script>
<script src=""></script>
</div>
</div>
</body>
</html>
Tôi mới cho Backbone.JS. Cảm ơn vì sự giúp đỡ.
Hey, Cảm ơn các đáp ứng! Điều đó đã loại bỏ lỗi cũ, nhưng bây giờ tôi đang nhận được một lỗi mới: 'Loại không bắt buộcLỗi: Không thể đọc thuộc tính' 1 'của null backbone.js: 1062 _.extend.delegateEvents backbone.js: 1062 Xương sống. Xem backbone.js: 988 child backbone.js: 1531 (chức năng ẩn danh) pageLoader.js: 19 (chức năng ẩn danh) ' –
@JoshV Bạn không thể có khóa sự kiện trống. – Andrew
Ohh Được rồi, tôi hiểu. Sai lầm của tôi đã nghĩ rằng nó có cấu trúc giống như Backbone.Router. Tôi thử cái này –