PathJS - 未捕获的类型错误:对象#<对象>没有方法“默认”; (匿名函数)对象>
我正在尝试使用 PathJS,并在控制台中收到以下错误:(
Uncaught TypeError: Object #<Object> has no method 'default'
匿名函数)
我正在使用以下教程: http://mtrpcic.net/2011/02/fragment-uris-theyre-not-as-bad-as-you -think-really/
使用插件:https://github.com/mtrpcic/pathjs
我的应用程序加载 jQuery,然后加载 PathJS 插件,然后加载 app.js 中的这段代码:
$("a").live("click", function(event){
var href = $(this).attr("href");
if(href[0] == "/"){
event.preventDefault();
window.location.hash = "#!" + href;
}
});
Path.default(function(){
$.get(window.location.hash.replace("#!", ""), function(data){
$("#contents").html(data);
});
});
Path.listen();
有什么想法为什么我会收到错误吗?
I'm trying to use PathJS, and get the following error in the console:
Uncaught TypeError: Object #<Object> has no method 'default'
(anonymous function)
I'm using the following tutorial: http://mtrpcic.net/2011/02/fragment-uris-theyre-not-as-bad-as-you-think-really/
With the plugin: https://github.com/mtrpcic/pathjs
My app loads jQuery then the PathJS plugin, then this code in app.js:
$("a").live("click", function(event){
var href = $(this).attr("href");
if(href[0] == "/"){
event.preventDefault();
window.location.hash = "#!" + href;
}
});
Path.default(function(){
$.get(window.location.hash.replace("#!", ""), function(data){
$("#contents").html(data);
});
});
Path.listen();
Any ideas why I'm getting the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
Path.listen()
应该这样包装:如果您已经这样做了(从上面的代码中看来并非如此,但您可能只是没有包含该部分),那么我会质疑您的
Path.default
代码。我在文档中没有看到任何有关默认路径的信息。但是,有一个Path.root
,但您仍然需要为其提供一条路线。我想知道这是否可能在某个时候从代码中删除,正如我在您提到的教程中看到的那样。Your
Path.listen()
should be wrapped up like this:If you are already doing that ( it doesn't appear so from the code above, but you may have just not included that part ) then I would question your
Path.default
code. I see nothing about a default path in the documentation. There is however, aPath.root
, but you still need to provide it a route. I'm wondering if that may have been removed from the code at some point, as I do see it mentioned on the tutorial you mentioned.