我正在构建一个项目管理应用程序,我想跟踪用户工作的开始和停止时间。
所以我在UI中有两个按钮, START AND STOP 如果用户点击 START 按钮,下面的功能将获得当前时间
$scope.start =function(){
$scope.begin = moment(new Date());
}
如果用户点击停止按钮,则此功能将获得当前时间
$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
答案 0 :(得分:2)
这很简单,因为你已经完成了它!
//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.
}