2016-03-01 68 views
0

我有一个包含“完成”按钮的待办事项列表。我想在每次用户点击按钮时将时间存储在firebase中。该按钮启用一段时间后,当用户再次单击该按钮时,我想再次存储时间并且不覆盖现有时间。在我的代码中,时间被覆盖。每次用户点击一个按钮时,在“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; 
    } 

}; 

回答

1

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

鉴于裁判是你的根裁判

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

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

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

"timestamps": { 
    "-QIUEiijasdj923498": { 
     "stamp": "a timestamp" 
    }, 
    "-Qnbnajsd093409koi": { 
     "stamp": "a timestamp" 
    } 
相关问题