Javascript 未处理的拒绝(错误):Reference.set失败:第一个参数在属性';注册。测试。机器人。道具。历史。位置。状态';
我的react文件中的切换按钮不会向firebase发送任何数据。代码返回此错误:未处理的拒绝(错误):Reference.set失败:第一个参数在属性“signup.test.Robots.props.history.location.state”中包含未定义的内容 我也定义了我所有的道具。如果你发现一个错误,请帮助我 按钮:Javascript 未处理的拒绝(错误):Reference.set失败:第一个参数在属性';注册。测试。机器人。道具。历史。位置。状态';,javascript,html,reactjs,firebase,firebase-realtime-database,Javascript,Html,Reactjs,Firebase,Firebase Realtime Database,我的react文件中的切换按钮不会向firebase发送任何数据。代码返回此错误:未处理的拒绝(错误):Reference.set失败:第一个参数在属性“signup.test.Robots.props.history.location.state”中包含未定义的内容 我也定义了我所有的道具。如果你发现一个错误,请帮助我 按钮: <div data-toggle="buttons" class="btn-group bizmoduleselect mt-2
<div data-toggle="buttons" class="btn-group bizmoduleselect mt-2 lg:w-1/3">
<label class="btn btn-default mx-1 rounded " >
<div class="bizcontent py-2" id="bizcontent">
<input type="checkbox" id="checkbox" name="Space" autocomplete="off" value="Space" hidden
checked={this.state.isSpace}
onChange={this.onChangeSpace} />
<span class="glyphicon glyphicon-ok glyphicon-lg"></span>
<p>Space</p>
</div>
</label>
<label class="btn btn-default mx-1 rounded">
<div class="bizcontent py-2 " >
<input type="checkbox" id="checkbox" name="Robots" autocomplete="off" value="Robots" hidden
checked={this.state.Robots}
onChange={this.onChangeRobots}/>
<span class="glyphicon glyphicon-ok glyphicon-lg"></span>
<p>Robots</p>
</div>
</label>
<label class="btn btn-default mx-1 rounded">
<div class="bizcontent py-2">
<input type="checkbox" name="Magic" autocomplete="off" value="Magic" hidden
checked={this.state.isMagic}
onChange={this.onChangeMagic} />
<span class="glyphicon glyphicon-ok glyphicon-lg"></span>
<p>Magic tricks</p>
</div>
</label></div>
正在向firebase发送数据:
import firebase from '../firebase.js';
export function register(email, name, age, phone_number, isSpace, Robots, Magic, isArt, isMusic, _this) {
firebase.database().ref('/signup/' + name).once('value').then(function (snapshot) {
if (snapshot.val() === null || snapshot.val() === undefined) {
firebase.database().ref('signup/' + name).set({
name: name,
age: age,
email: email,
phone_number: phone_number,
isSpace: isSpace,
Robots: Robots,
Magic: Magic,
});
}
});
}
错误消息告诉您向
set()
传递了无效值。仔细阅读:
Reference.set失败:第一个参数在属性“signup.test.Robots.props.history.location.state”中包含未定义的
这意味着路径
signup.test.Robots.props.history.location.state
的值未定义。因此,听起来像是作为Robots
传递的任何东西都包含一个未定义的嵌套属性props.history.location.state
。您必须进行一些调试以找出原因。在将Robots
属性内容发送到firebase之前,您可以记录它吗?是的,我尝试使用console.log,但控制台上没有打印任何内容(状态似乎没有改变?)
import firebase from '../firebase.js';
export function register(email, name, age, phone_number, isSpace, Robots, Magic, isArt, isMusic, _this) {
firebase.database().ref('/signup/' + name).once('value').then(function (snapshot) {
if (snapshot.val() === null || snapshot.val() === undefined) {
firebase.database().ref('signup/' + name).set({
name: name,
age: age,
email: email,
phone_number: phone_number,
isSpace: isSpace,
Robots: Robots,
Magic: Magic,
});
}
});
}