“未捕获的TypeError:未定义不是函数" Firebase上的错误 [英] "Uncaught TypeError: undefined is not a function" error on firebase

查看:97
本文介绍了“未捕获的TypeError:未定义不是函数" Firebase上的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web开发的新手,我遇到了Firebase错误.

I'm very new to web development and I have an error with firebase error.

我正在使用Firebase和jQuery制作一个可识别语音并将其转换为文本的Web应用程序. (语音转文本,STT)

I'm using Firebase and jQuery to make an web application which recognizes voice and translates it to text. (Speech-to-Text, STT)

我必须实时推送STT结果,以便所有客户端都能看到文本.

I have to push the STT results in realtime so that all clients could see the text.

但是,此事件侦听器中出现了问题:

However, the problem occurs in this event listener:

finalSTTField.click(function (e) {
        var message = finalSTTField.val();
        sttRef.push({ text: message } );
    });

作为STT的结果,在finalSTTField中有一个字符串,其声明如下:

As a result of STT, a string is in the finalSTTField which is declared like below:

var finalSTTField = $('#final_span');

我想使用Firebase推送字符串:

And I want to push the string by using the firebase:

var sttRef = new Firebase('https://sizzling-torch-2935.firebaseio.com/');

<div class="sttResultContainer">
    <ul id="sttMessages"></ul>
</div>

使用

var sttResults = $('#sttMessages');

sttRef.limitToLast(10).on('child_added', function (snapshot) {
        var data = snapshot.val();
        var sttText = data.value();

        var messageElement = $("<li>");
        messageElement.text(sttText);
        sttResults.append(messageElement);
        sttResults[0].scrollTop = sttResults[0].scrollHeight;
    });

但是sttResults中什么都没有显示.

But nothing shows in sttResults.

Chrome浏览器上的错误消息是: firebase.js:26 未捕获的TypeError:undefined不是函数

The error message on chrome browser is: firebase.js:26 Uncaught TypeError: undefined is not a function

每次单击事件发生时,错误计数都会增加. (奇怪的是,计数从10开始)

Error count increases every time the click event occurs. (Strangely, the count starts at 10)

第一个STT成绩单在#final_span跨度中显示良好. 但是我必须实时在#final_span中推送字符串...

The first STT transcripts are showing well in the #final_span span. But I have to push the string in #final_span in realtime...

请有人帮我!这是我的第一个Web应用程序...

Somebody help me please! It's my first web application...

完整的源代码在这里: JSFiddle中的完整源代码

Full source code is here: full source in JSFiddle

推荐答案

此行是错误的:

var sttText = data.value();

在快照上调用val()以获取值后,您将获得一个JSON对象.没有在该对象上定义任何方法.相反,您的文本位于子属性中,因此您可以像这样获得它:

After you call val() on the snapshot to get the value, you get a JSON object. No methods are defined on that object. Your text is instead in a child property, so you can get it like:

var data = snapshot.val();
var sttText = data.text;

请注意,如果在提取数据后放置console.log语句,则很容易找到这样的问题:

Note that it is fairly easy to find such a problem, if you put a console.log statement after extracting the data:

var data = snapshot.val();
console.log(data);

这是非常的常见故障排除技术.在您的小提琴中打印:

This is a very common troubleshooting technique. In your fiddle it prints:

对象{text:"}

Object {text: ""}

这篇关于“未捕获的TypeError:未定义不是函数" Firebase上的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆