gpt4 book ai didi

javascript - 每次用户单击按钮时,将 'time' 存储在 firebase 中

转载 作者:行者123 更新时间:2023-12-03 07:33:10 25 4
gpt4 key购买 nike

我有一个带有“完成”按钮的待办事项列表。我想在每次用户单击按钮时将时间存储在 firebase 中。该按钮在一段时间后启用,当用户再次单击该按钮时,我想再次存储时间而不是覆盖现有时间。在我的代码中,时间被覆盖。

index.html

<ion-list class = "list">
<ion-item class = "has-header" ng-repeat="todo in data.todos" class = "item" ng-class="{purchased: todos.status == 'purchased'}">
{{todo.title}}
<button ng-disabled="todo.stopSpam" ng-click="doneItem(todo)">Done
</button>

app.js

$scope.doneItem = function(todo) {

todo.stopSpam = true;
todo.timestamp = Date();

$interval(callAtInterval, 30000);

function callAtInterval(){
todo.stopSpam = false;
}

};

最佳答案

为了避免覆盖现有数据,每次您想要在该节点中存储数据时,您的代码都应该创建新的子节点。

给定的引用是您的根引用

var timestampsRef = ref.child("timestamps");
var newTimestampRef = timestampsRef.push();

newTimestampRef.set({
stamp: "a timestamp"
});

每次用户按下按钮时调用它都会创建一个不同的节点名称,然后将时间戳作为子节点添加到每个节点。

  "timestamps": {
"-QIUEiijasdj923498": {
"stamp": "a timestamp"
},
"-Qnbnajsd093409koi": {
"stamp": "a timestamp"
}

关于javascript - 每次用户单击按钮时,将 'time' 存储在 firebase 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35728935/

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