你好bhawna這個代碼必須幫助你... 考勤客戶端爲用戶考勤碼..index.html
<html>
<head>
<title>Attendence</title>
<script src="angular.min.js"></script>
</head>
<body bgcolor="gray">
<a href="Shistory.html">Attendence Listing</a>
<div id="container" >
<h1 align="center"> Attendence </h1>
<div align="center">
<form method="post" name="ravi" action="/">
<input type="text" placeholder="Name" name="Item" required><br/>
date :<input type="number" placeholder="year" name="year" min="2015" max="2017" required>
<input type="number" placeholder="month" name="month" min="1" max="12" required>
<input type="number" placeholder="day" name="day" min="1" max="31" required><br/>
attended:<select name="attended">
<option value="Present">Present</option>
<option value="Absent">Absent</option>
</select>
<br/>
<input type="submit" value="Insert attendence" >
</form>
</div>
</div>
</body>
</html>
以及使用日期代碼搜索用戶的代碼.. Shistor y.html
<html>
<head>
<title>Attendence</title>
<script src="angular.min.js"></script>
</head>
<body bgcolor="gray">
<a href="index.html">Attendence</a>
<div id="container" >
<div align="center">
<h1 align="center"> Attendence Listing </h1>
<form method="post" name="ravi1" action="/a">
date :<input type="number" placeholder="year" ng-model="year" name="year" min="2015" max="2017" required>
<input type="number" placeholder="month" ng-model="month" name="month" min="1" max="12" required>
<input type="number" placeholder="day" ng-model="day" name="day" min="1" max="31" required><br/>
<input type="submit" value="attendence">
</form>
</div>
</div>
</body>
</html>
和你的服務器端代碼.. server.js
var MongoClient = require('mongodb').MongoClient;
var connect = require('connect'),
bodyParser = require('body-parser')
var ObjectId=require('mongodb').ObjectID;
var BSON = require('mongodb').pure().BSON,
express = require("express"),
app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
// app.use(express.bodyParser());
app.use(express.static(__dirname + '/angular'));
// index.html and Sdistory.html in public folder
app.use(express.static(__dirname + '/public'));
app.get("/",function(req,res){
res.sendFile(__dirname+'/index.html');
});
MongoClient.connect("mongodb://localhost:27017/bhawna", function(err, db) {
if(err) { return console.dir(err); }
var collection2 = db.collection('users');
app.post('/a',function(req,res){
//console.log("hello");
var qqw=req.body.year;
var qqw2=req.body.month;
var qqw3=req.body.day;
collection2.find({'Scheduledtime':(new Date(qqw, (qqw2-1), qqw3)).toLocaleString()}).toArray(function(err,resu)
{
res.end(JSON.stringify(resu));
console.log(resu);
}
);
});
app.post('/',function(req,res){
var searchitem =(req.body.Item).toUpperCase();
var yr=req.body.year;
var moy=req.body.month;
var dom=req.body.day;
var attended=req.body.attended;
collection2.insert({'userd':searchitem,'Scheduledtime':(new Date(yr, (moy-1), dom)).toLocaleString(),'Attended':attended},function(err,result){});
res.setHeader("Access-Control-Allow-Origin","http://localhost:8080/")
re
s.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type");
res.redirect('back');
});
});
app.listen(8080,function(){
console.log("It's Started on PORT 8080");
});
而你在哪裏停留在所有這些任務?你不知道如何查詢mongo嗎?或者你有麻煩顯示結果的角度?你試過什麼了? – joao 2015-02-07 10:54:55
順便說一句,Mongo具有[日期類型](http://docs.mongodb.org/manual/reference/bson-types/),因此您不必像那樣存儲它。 – laggingreflex 2015-02-07 11:21:42
與日期類型它也顯示時間。我不想要時間becauz造成歧義。我想存儲每個用戶的特定日期的單個記錄 – 2015-02-09 06:08:42