[英]“Uncaught TypeError: undefined is not a function” error on firebase
I'm very new to web development and I have an error with firebase error. 我是Web开发的新手,我遇到了Firebase错误。
I'm using Firebase and jQuery to make an web application which recognizes voice and translates it to text. 我正在使用Firebase和jQuery制作一个可识别语音并将其转换为文本的Web应用程序。 (Speech-to-Text, STT)
(语音转文本,STT)
I have to push the STT results in realtime so that all clients could see the text. 我必须实时推送STT结果,以便所有客户端都能看到文本。
However, the problem occurs in this event listener: 但是,此事件侦听器中出现问题:
finalSTTField.click(function (e) {
var message = finalSTTField.val();
sttRef.push({ text: message } );
});
As a result of STT, a string is in the finalSTTField which is declared like below: 作为STT的结果,字符串在finalSTTField中,其声明如下:
var finalSTTField = $('#final_span');
And I want to push the string by using the firebase: 我想使用firebase推送字符串:
var sttRef = new Firebase('https://sizzling-torch-2935.firebaseio.com/');
and 和
<div class="sttResultContainer">
<ul id="sttMessages"></ul>
</div>
with 同
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;
});
But nothing shows in sttResults. 但是sttResults中没有任何显示。
The error message on chrome browser is: firebase.js:26 Uncaught TypeError: undefined is not a function chrome浏览器上的错误消息是:firebase.js:26 Uncaught TypeError:undefined不是一个函数
Error count increases every time the click event occurs. 每次单击事件发生时,错误计数都会增加。 (Strangely, the count starts at 10)
(奇怪的是,计数从10开始)
The first STT transcripts are showing well in the #final_span span. 第一个STT成绩单在#final_span跨度中显示良好。 But I have to push the string in #final_span in realtime...
但是我必须实时在#final_span中推送字符串...
Somebody help me please! 请有人帮我! It's my first web application...
这是我的第一个Web应用程序...
Full source code is here: full source in JSFiddle 完整的源代码在这里: JSFiddle中的完整源代码
This line is wrong: 这行是错误的:
var sttText = data.value();
After you call val()
on the snapshot to get the value, you get a JSON object. 在快照上调用
val()
以获取值之后,您将获得一个JSON对象。 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;
Note that it is fairly easy to find such a problem, if you put a console.log
statement after extracting the data: 请注意,如果在提取数据后放置
console.log
语句,则很容易找到这样的问题:
var data = snapshot.val();
console.log(data);
This is a very common troubleshooting technique. 这是一种非常常见的故障排除技术。 In your fiddle it prints:
在您的小提琴中打印:
Object {text: ""}
对象{text:“”}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.