backbone.js 控制器不工作
我做错了什么?
html:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="js/libs/underscore.js"></script>
<script src="js/libs/backbone.js"></script>
<script src="js/libs/json2.js"></script>
<script src="js/script.js"></script>
script.js 文件:
Controller = Backbone.Controller.extend({
routes: {
':name': 'respond'
},
respond : function(name) {
console.log('it works!');
}
});
var controller = Controller;
What am I doing wrong?
html:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="js/libs/underscore.js"></script>
<script src="js/libs/backbone.js"></script>
<script src="js/libs/json2.js"></script>
<script src="js/script.js"></script>
script.js file:
Controller = Backbone.Controller.extend({
routes: {
':name': 'respond'
},
respond : function(name) {
console.log('it works!');
}
});
var controller = Controller;
Now when I enter http://localhost/backbonetest/#somethink nothink happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要路由绑定工作,请在初始化控制器后使用此代码:
资源:http:// documentcloud.github.com/backbone/#History-start
现在,如果您输入:
您将在控制台中看到“它有效”。
I You want Your route bind's work, use this code after initializing your controllers:
resource: http://documentcloud.github.com/backbone/#History-start
Now if you type:
You will see 'it works' in Your console.
请使用浏览器的 JavaScript 控制台查看错误日志。我发现 Chrome 更擅长 JavaScript 调试,因为它比其他浏览器更难容忍 JavaScript 错误
Please use your browsers JavaScript console to see the error log. I find chrome to be better at JavaScript debugging because it's less forgiving to JavaScript errors than other browsers