[英]DHTMLX Scheduler with Node JS
我已经遵循了DTHMLX Scheduler 教程 ,但是我无法使db.event.insert()
正常工作,因为它的路由没有触发。 但是,当我通过外壳插入数据时,我能够显示MongoDB中的数据。
像本教程一样,我使用MongoSkin作为MongoDB驱动程序。 本教程中的MongoSkin和Express均为同一版本"mongoskin": "~0.6.0"
和"express": "~3.3.8"
"mongoskin": "~0.6.0"
。
<!-- index.html -->
<!doctype html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Basic initialization</title>
</head>
<script src="codebase/dhtmlxscheduler.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="codebase/dhtmlxscheduler.css" type="text/css" media="screen" title="no title" charset="utf-8">
<style type="text/css" media="screen">
html, body{
margin:0px;
padding:0px;
height:100%;
overflow:hidden;
}
</style>
<script type="text/javascript" charset="utf-8">
function init() {
scheduler.config.xml_date="%Y-%m-%d %H:%i"; //changes date format
scheduler.init('scheduler_here',new Date(),"month"); // when the calendar is initialized
scheduler.templates.xml_date = function(value){ return new Date(value); };
scheduler.load("/data", "json");
var dp = new dataProcessor("/data");
dp.init(scheduler);
dp.setTransactionMode("POST", true);
console.log('init on index finished');
}
</script>
<body onload="init();">
<div id="scheduler_here" class="dhx_cal_container" style='width:100%; height:100%;'>
<div class="dhx_cal_navline">
<div class="dhx_cal_prev_button"> </div>
<div class="dhx_cal_next_button"> </div>
<div class="dhx_cal_today_button"></div>
<div class="dhx_cal_date"></div>
<div class="dhx_cal_tab" name="day_tab" style="right:204px;"></div>
<div class="dhx_cal_tab" name="week_tab" style="right:140px;"></div>
<div class="dhx_cal_tab" name="month_tab" style="right:76px;"></div>
</div>
<div class="dhx_cal_header">
</div>
<div class="dhx_cal_data">
</div>
</div>
</body>
服务器文件像本教程一样是基本内容。 服务器文件从app.js更改为server.js。
//server.js
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var db = require('mongoskin').db("mongodb://localhost:27017/testdb", { w: 0});
db.bind('event');
var app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.bodyParser());
app.get('/init', function(req, res){
if (err) throw err;
console.log('before object');
db.event.insert({
text:"My test event A",
start_date: new Date(2017,5,1),
end_date: new Date(2017,5,5)
}, console.log('first object run'));
db.event.insert({
text:"My test event B",
start_date: new Date(2017,5,19),
end_date: new Date(2017,5,24)
});
db.event.insert({
text:"Morning event",
start_date: new Date(2017,5,4),
end_date: new Date(2017,5,4)
});
db.event.insert({
text:"One more test event",
start_date: new Date(2017,5,3),
end_date: new Date(2017,5,8),
color: "#DD8616"
});
res.send("Test events were added to the database");
console.log('events inserted?')
});
app.get('/data', function(req, res){
db.event.find().toArray(function(err, data){
//set id property for all records
for (var i = 0; i < data.length; i++)
// console.log('in for loop');
data[i].id = data[i]._id;
//output response
res.send(data);
console.log('data sent');
});
});
app.listen(3000);
console.log('listening on port 3000');
我可以使用app.get('/data'
路由和回调函数,并将我的收藏集打印到日历上,但app.get('/data'
将其插入MongoDB的shell命令行中。
插入数据也可以db.event.insert
说,因为错过了db.event.insert
方法,因为app.get('/init'
路由从未触发过。我从测试中发现,使用console.logs。
我通读了DHTMLX Scheduler教程,网站文档,MongoDB文档和MongoSkin文档。 我可能会完全错过一个显而易见的解决方案,但是我似乎找不到在这里找到的东西,因此我们将不胜感激。 谢谢。
但是我无法使db.event.insert()正常工作,因为它的路由没有触发。
似乎您的代码没有POST / data请求的路由,当您在客户端上插入/更新/删除项目时会调用该路由。 这是样本https://github.com/DHTMLX/node-scheduler-demo/blob/master/app.js#L52中的相关代码
关于GET / init路由-它仅用于将一些测试数据插入db,并且被手动调用。 您可以删除它,而对应用程序的其余部分没有任何影响
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.