簡體   English   中英

未捕獲的TypeError:undefined不是函數

[英]Uncaught TypeError: undefined is not a function

我有一個腳本,可提取json數據並將其轉換為可讀格式。

它返回錯誤: Uncaught TypeError: undefined is not a functioncontainer.append($.nano(template, events[0]));上的Uncaught TypeError: undefined is not a function container.append($.nano(template, events[0]));

我試圖找到關於stackoverflow的答案,包括:

  • 確保首先加載jQuery
  • 將功能包裝到文檔中
  • 只包含一次jQuery

我已經完成了上述所有工作,並在此jsfiddle中復制了問題

http://jsfiddle.net/FXcX3/

您錯誤地調用了nano,這不是jQuery的方法。 應該是這樣的(來自文檔 ):

container.append(nano(nogig));

http://jsfiddle.net/4pe3j/1/

nano is on line 244 in the fiddle. I'm not sure where I'm not defining it.

在那一行上,您有:

function nano(template, data) {
    return template.replace(/\{([\w\.]*)\}/g, function (str, key) {
        var keys = key.split("."),
            v = data[keys.shift()];
        for (var i = 0, l = keys.length; i < l; i++) v = v[keys[i]];
        return (typeof v !== "undefined" && v !== null) ? v : "";
    });
}

這是在全局范圍內定義的,因此將$.nano更改為nano

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM