dan*_*uxx 1 javascript firebase firebase-realtime-database
我想将子状态更新为 Active,但我真的不知道如何解决这个问题。我想更新一个特定的记录,我正在使用表 btw。我已经被困在这里了。请帮我。谢谢!
<script>
// Get a reference to the database service
var database = firebase.database();
database.ref('Users').orderByChild('usertype').equalTo('Property Owner').on('value', function(snapshot) {
if (snapshot.exists()) {
var content = '';
snapshot.forEach(function(data) {
var stat = data.val();
if (stat.status == 'Inactive') {
var val = data.val();
content += '<tr>';
content += '<td>' + val.fname + '</td>';
content += '<td>' + val.mname + '</td>';
content += '<td>' + val.lname + '</td>';
content += '<td>' + val.email + '</td>';
content += '<td>' + val.registered + '</td>';
content += '<td>' + val.status + '</td>';
content += '<td><button type="button" id="button" style="font-size: 12px;class="btn btn-danger" onclick="myFunction()">Update Status</button></td>';
content += '</tr>';
}
});
}
$('#ex-table').append(content);
});
function myFunction() {
alert('');
}
</script>
Run Code Online (Sandbox Code Playgroud)
好的,让我来分析一下,您要做的是更新一个字段。您可以在此处的文档中找到有关如何执行此操作的信息,但基本上您需要做的是构建对要修改的特定用户的引用,然后对其调用 update。所以,无论你听什么按钮,你都想做类似的事情
firebase.database().ref().update({'users/USERNAME/status': "Active"})
Run Code Online (Sandbox Code Playgroud)
其中 USERNAME 是您要更新的特定用户的名称。
| 归档时间: |
|
| 查看次数: |
2423 次 |
| 最近记录: |