2017-12-18 177 views
3

我正在構建一個項目管理應用程序,我想跟蹤用戶工作的開始和停止時間。使用NodeJS將啓動和停止時間轉換爲mysql(sequelize)

所以我要在UI兩個按鈕,啓動和停止如果用戶點擊START按鈕,這下面的功能將得到當前的時間

$scope.start =function(){ 
    $scope.begin = moment(new Date()); 
} 

如果用戶點擊STOP按鈕,這下面的功能將獲得當前時間

$scope.stop =function(){ 
    $scope.end = moment(new Date()); 
} 

所以我想在這種類型的對象中獲得兩個數據$ scope.begin和$ scope.end:

{ 

    time:[ 

     { begin: 3:59:1 Dec/18/2017 ; end:5:59:1 Dec/18/2017 }, 
     //if user click again start and stop i want another object dynamically 
     { begin: 5:59:1 Dec/18/2017 ; end:6:59:1 Dec/18/2017 } 
     { begin: 5:59:1 Dec/18/2017 ; end:6:59:1 Dec/18/2017 } 
     { begin: 5:59:1 Dec/18/2017 ; end:6:59:1 Dec/18/2017 } 
     //dynamically want add this objects by user operations 

    ] 

} 

如何做到這一點我使用angularjs和的NodeJS

回答

3

這是非常簡單的,因爲你已經做到了!

//create your time data object 
 
//or maybe get it from your server 
 
$scope.timeData = { 
 
    time:[] 
 
} 
 

 

 
$scope.start =function(){ 
 
    $scope.begin = moment(new Date()); 
 
} 
 

 
$scope.stop =function(){ 
 
    $scope.end = moment(new Date()); 
 
    $scope.timeData.time.push({ 
 
     begin: $scope.begin, 
 
     end: $scope.end 
 
    }) 
 
    
 
    //and maybe post your timeData to server in order to save them. 
 
}