当我的函数有回调函数时,获取回调函数不是函数

时间:2022-03-16 21:01:11

I do not understand why I keep getting the error message: uncaught type error: callback is not a function. I clearly have a callback function in my giveTrack function. Any insight?

我不明白为什么我一直收到错误消息:未捕获类型错误:回调不是一个函数。我在giveTrack函数中显然有一个回调函数。任何见解?

function giveTrack(track, elementid) {
    SC.oEmbed(track, {
        auto_play: false,
        maxheight: 125,
        maxwidth: 300
    }, document.getElementById(elementid), function(oEmbed) {
        console.log(oEmbed.html);
    });

}


var looper = 0;
for (x in djlist) {
    SC.get('/users/' + djlist[x] + '/tracks', function(tracks) {
        console.log(tracks[0]);
        myTrack = tracks[0].permalink_url;
        var g = document.createElement('div');
        g.id = "hello" + looper;
        document.createElement('br');
        giveTrack(myTrack, "hello" + looper);

        looper++;
    });
}

1 个解决方案

#1


The SC.oEmbed method takes either an element:

SC.oEmbed方法接受一个元素:

SC.oEmbed(url, options, element);

or a callback:

或者回调:

SC.oEmbed(url, options, callback);

You are trying to use both an element and a callback. The method will ignore the fourth parameter, and try to determine the type of the third parameter.

您正在尝试使用元素和回调。该方法将忽略第四个参数,并尝试确定第三个参数的类型。

You have created an element with a specific id, but you haven't added that element to the page. When you use getElementById to find the element, you will get null back.

您已创建具有特定ID的元素,但尚未将该元素添加到页面。当您使用getElementById查找元素时,您将返回null。

Because the third parameter is null, the method can't determine if it's supposed to be an element or a callback, so apparently it assumes a callback. As the reference is null, it can't be used as a function.

因为第三个参数为null,所以该方法无法确定它是应该是元素还是回调,所以显然它假设是回调。由于引用为null,因此不能将其用作函数。

Ref: https://developers.soundcloud.com/docs/api/sdks#embedding

#1


The SC.oEmbed method takes either an element:

SC.oEmbed方法接受一个元素:

SC.oEmbed(url, options, element);

or a callback:

或者回调:

SC.oEmbed(url, options, callback);

You are trying to use both an element and a callback. The method will ignore the fourth parameter, and try to determine the type of the third parameter.

您正在尝试使用元素和回调。该方法将忽略第四个参数,并尝试确定第三个参数的类型。

You have created an element with a specific id, but you haven't added that element to the page. When you use getElementById to find the element, you will get null back.

您已创建具有特定ID的元素,但尚未将该元素添加到页面。当您使用getElementById查找元素时,您将返回null。

Because the third parameter is null, the method can't determine if it's supposed to be an element or a callback, so apparently it assumes a callback. As the reference is null, it can't be used as a function.

因为第三个参数为null,所以该方法无法确定它是应该是元素还是回调,所以显然它假设是回调。由于引用为null,因此不能将其用作函数。

Ref: https://developers.soundcloud.com/docs/api/sdks#embedding