redditor
redditor

Reputation: 4276

Uncaught TypeError: undefined is not a function

I have a script that pulls json data and converts it to a readable format.

It is returning the error: Uncaught TypeError: undefined is not a function on the line container.append($.nano(template, events[0]));

I have tried to find answers on stackoverflow which include:

I have done all of the above and have replicated the problem in this jsfiddle

http://jsfiddle.net/FXcX3/

Upvotes: 0

Views: 719

Answers (2)

Abraham Hamidi
Abraham Hamidi

Reputation: 13799

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

On that line, you have this:

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 : "";
    });
}

This is defined on the global scope, so change $.nano to nano.

Upvotes: 1

net.uk.sweet
net.uk.sweet

Reputation: 12431

You're calling nano incorrectly, it's not a method of jQuery. It should be like this (from the documentation):

container.append(nano(nogig));

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

Upvotes: 2

Related Questions