我在Web App中使用Firebase数据库,并且还有这样的数据:
如何删除标题中标有“Apple”的整个记录(标记在图片中)?
我写了下面的代码,但它没有用。
请帮助。
<div class="container-fluid">
<form id="formset" class="form-inline" action="" method="post"> <!--added id="formset" to the form element-->
{% csrf_token %}
{{ form }}
<table class="table">
{{ formset_new.management_form }}
<div>
<br><h4><strong>New</strong></h4><br>
{% include "reports/formsets.html" with formset=formset_new formset_class_name='new' prefix="new" %}
</div>
</table>
<table class="table">
{{ formset_renewal.management_form }}
<div>
<br><h4><strong>Renewals</strong></h4><br>
{% include "reports/formsets.html" with formset=formset_renewal formset_class_name='renewal' prefix="renewal" %}
</div>
</table>
</div>
</form>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="{% static 'js/jquery.formset.js' %}"></script>
<br>
<div class="container">
<!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal"><strong>Submit</strong></button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Before You Submit!!</h4>
</div>
<div class="modal-body">
<p>Please review and make sure that all line items are correct and that the <strong>"Check if No New Items"</strong> is checked if there are no new items for that catagory. If all is correct, please select the <strong>Save and Email</strong> button.</p>
</div>
<div class="modal-footer">
<input type="submit" form="formset" class="btn btn-primary" value="Save and Email to Corporate"><!--added form id, form="formset" , to input element-->
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
它没有在控制台中给我任何错误。
答案 0 :(得分:1)
您正在订购/过滤错误的属性。你有title
属性的值,所以应该对它进行排序:
var abc = firebase.database().ref('firebase-test');
var key_to_delete = 'Apple';
var query = abc.orderByChild('title').equalTo(key_to_delete);
query.on('child_added', function(snapshot)
{
snapshot.ref.remove();
});
备选方案,因为您知道要删除的项目的键,所以您也可以在没有查询的情况下删除该项目:
var abc = firebase.database().ref('firebase-test');
abc.child("KISNx87aYigsH3ILp0D").remove();