gpt4 book ai didi

html - 错误 : Reference. 推送失败:第一个参数在属性中包含一个函数 - firebase

转载 作者:行者123 更新时间:2023-12-04 21:05:47 25 4
gpt4 key购买 nike

我正在尝试将值推送到我的 firebase 数据库中。当我尝试推送值时,它在控制台中给我一个错误(错误:Reference.push failed: first argument contains a function in property)。我在 firebase 上查了一下,发现是因为一个函数被推送了,但我根本没有推送任何函数。但我有一种感觉,这可能是因为 datetimepicker。需要帮忙!

我的JS

/*global angular*/
var app = angular.module('downtime', ['ngRoute', 'firebase']);

app.config(['$routeProvider', function ($routeProvider) {
'use strict';
$routeProvider.when('/downtime', {
templateUrl: 'downtime/downtime.html',
controller: 'downtimeCtrl'
});
}]);

app.controller('downtimeCtrl', ['$scope', '$firebaseObject', '$firebaseArray', function ($scope, $firebaseObject, $firebaseArray) {
'use strict';

$scope.allEquipments = [];
$scope.allSystems = [];

$scope.manageDowntime = function () {

var doesExist = false;
angular.forEach ($scope.data , function (d) {
angular.forEach (d.equipments, function (e) {
})
});
firebase.database().ref('downtime/' + $scope.equipment + '/downtime').push({
equipment: $scope.equipment,
type : $scope.type,
start: $scope.startDT,
end: $scope.endDT
});
};

var ref = firebase.database().ref();
var data = ref.child("data");
var list = $firebaseArray(data);

list.$loaded().then(function(data) {
$scope.data = data;
angular.forEach ($scope.data , function (d) {

$scope.allSystems.push(d.$id);

angular.forEach (d.equipments, function (e) {
$scope.allEquipments.push(e.equipment);
console.log($scope.allEquipments);
})
});
console.log($scope.data);
}).catch(function(error) {
$scope.error = error;
});

$('#datetimepicker1').datetimepicker();
$('#datetimepicker2').datetimepicker();

}]);

app.directive('customzdatetime', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
element.datetimepicker({
debug: false,
format: 'DD-MM-YYYY hh:mm'
}).on('dp.change', function (e) {
ngModelCtrl.$setViewValue(e.date);
scope.$apply();
});
}
};
});

我的 HTML
<div class="page-header">
<h1>MANAGE DOWNTIME </h1>
</div>
<div data-ng-app="downtime">

<div class="row">
<div class="col-xs-12">

<div class="form-group col-xs-6 col-xs-offset-3" id="equipList">
<label for="selectequ">Select Equipment</label>
<select class="form-control" id="selectequ" data-ng-model="equipment"
>
<option data-ng-repeat="eq in allEquipments" >{{eq}}</option>
</select>

{{equipment}}
</div>

<div class="form-group col-xs-6 col-sm-6 col-md-6 col-lg-6 col-xs-offset-3" id="Type">
<label for="searchType">Search by Type:</label>
<select class="form-control" id="searchType" data-ng-model="type">
<option value="" disabled="" selected="" style="display: none">Select type of maintenance</option>
<option>Corrective Maintenance</option>
<option>Preventive Maintenance</option>
<option>Standby</option>
</select>
</div>

{{type}}

</div>
</div>

<div class="row">

<div class="form-group col-xs-6 col-xs-offset-3">
<label for="date">Start of Downtime</label>
<!-- <input type="datetime-local" id="datetimepicker1" class="form-control" placeholder="Day, Month, Year" data-ng-model="startDT"/>-->

<input type="text" class="form-control" placeholder="Day, Month, Year" data-ng-model="startDT" customzdatetime />
</div>
{{startDT}}
<div class="form-group col-xs-6 col-xs-offset-3">
<label for="date">End of Downtime</label>
<input type="text" class="form-control" placeholder="Day, Month, Year" data-ng-model="endDT" customzdatetime/>
{{endDT}}
</div>



</div>

<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6" id="central">
<a class="btn cd-add-to-cart cd-add-to-cart:hover cd-add-to-cart:active" role="button" data-ng-click="manageDowntime()">MANAGE <span class="glyphicon glyphicon-tasks"></span></a>
</div>
</div>

</div>

enter image description here

最佳答案

firebase 不接受 date 作为数据类型,尝试将它们转换为字符串或数字,然后尝试将其推送到 firebase 中。我希望你的问题是 $scope.startDT 因为它包含一些函数,你试图直接使用它,这就是它抛出错误的原因,尝试将它们转换为字符串或数字,然后尝试推送。

firebase.database().ref('downtime/' + $scope.equipment + '/downtime').push({
equipment: $scope.equipment,
type : $scope.type,
start: new Date($scope.startDT).toLocaleString(),
end: new Date($scope.endDT).toLocaleString()
or
start: new Date($scope.startDT).getTime(), //this will get you unix timestamp as number
end: new Date($scope.endDT).getTime()
});

关于html - 错误 : Reference. 推送失败:第一个参数在属性中包含一个函数 - firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46196049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com