【问题标题】:PathJS - Uncaught TypeError: Object #<Object> has no method 'default' (anonymous function)PathJS - Uncaught TypeError: Object #<Object> has no method 'default' (anonymous function)
【发布时间】:2011-06-07 01:05:02
【问题描述】:

我正在尝试使用 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();

任何想法为什么我会收到错误?

【问题讨论】:

  • Josh 的解决方案是否解决了这个问题?

标签: jquery jquery-plugins path.js


【解决方案1】:

你的Path.listen() 应该这样包裹起来:

$(document).ready(function() {
    Path.listen();
)};

如果您已经这样做了(从上面的代码中看不到,但您可能只是没有包含该部分),那么我会质疑您的 Path.default 代码。我在文档中看不到默认路径。但是,有一个Path.root,但您仍然需要为其提供路线。我想知道这是否可能已在某些时候从代码中删除,正如我在您提到的教程中看到的那样。

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    相关资源
    最近更新 更多