我正在尝试使用firebase并将数据保存到它。我正在阅读这些文档https://firebase.google.com/docs/database/rest/save-data
但我对如何使用submitToDB.addEventListener('click', function() {
if(document.getElementById('Hannah').checked){
liked.set(Hannah.value)
console.log('checked')
} else {
console.log('not checked')
}
});
命令感到困惑。
我有一个.json文件,我也有这个javascript文件,其中包含以下方法:
{
"users": {
"alanisawesome": {
"date_of_birth": "June 23, 1912",
"full_name": "Alan Turing"
}
}
}
Json文件:
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
$connect = mysql_connect("localhost", "root", "tert") or die(mysql_error());
mysql_select_db("ub", $connect) or die(mysql_error());
if(isset($_POST['status']))
{
$sql = "UPDATE admin SET Status = '".$_POST['status']."'
WHERE Status = '".$_POST['status']."'
";
$query = mysql_query($sql) or die(mysql_error());
}
?>
<table width = "70%" cellpadding = "5" cellspace = "5" >
<div class="row-fluid">
<div class="span6">
<table class="table table-responsive">
<thead>
<tr>
<td><strong> Last Name </td>
<td><strong> First Name </td>
<td><strong> Staff Id </td>
<td><strong> Status</td>
</tr>
<?php
while($row = mysql_fetch_array($query)) { ?>
<tr>
<td> <?php echo $row['lName']; ?> </td>
<td> <?php echo $row['fName']; ?> </td>
<td> <?php echo $row['staffId']; ?> </td>
<td><div contenteditable> <?php echo $row['Status']; ?> </td>
</tr>
<?php
}
?>
这将检查Hannah复选框是否被喜欢,然后将其添加到数据库中。但是,我无法从文档中找到如何添加大量JSON以及如何将用户输入JSON,然后以我想要的形式提交。
如果不清楚可以回答任何问题。
答案 0 :(得分:0)
如果您以前从未使用它,那么卷曲可能会令人困惑。无论如何,这是我在打字稿中使用的解决方案,但它也应该与javascript一起使用。
假设你有:
export class SubmitData {
_listPath:FirebaseListObservable<any>;
constructor(firebase:Firebase) {
const path = `/users/`;
//pass the path here
this._listPath = _firebase.database.list(path);
}
submitData() {
//Magic happens here. This works. Test it with my test app.
//Array object. Creates a user or users
let data = [
{
alanisawesome: "Genius",
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
},
{
fathersofSilicon: "Silicon Icon",
date_of_birth: "October 13, 1956",
full_name: "Marc Regis Hannah"
}
]
//This is how the push method works.
return this._listPath.push(data);
}
}