2017-07-02 12 views
0

DTHMLXスケジューラtutorialに従っていますが、db.event.insert()が動作するようにはできませんでした。しかし、シェルからデータを挿入するとMongoDBのデータを表示することができます。ノードJSを持つDHTMLXスケジューラ

チュートリアルと同様に、MongoSDBをMongoDBドライバとして使用しました。 MongoSkinとExpressの両方はチュートリアルにある通り同じバージョン"mongoskin": "~0.6.0" & "express": "~3.3.8"です。

<!-- 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">&nbsp;</div> 
      <div class="dhx_cal_next_button">&nbsp;</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'ルートやコールバック機能を使用することができていますし、私のコレクションは、カレンダー上に印刷しますが、唯一のMongoDBのシェルコマンドラインでそれを挿入した後。

app.get('/init'のルートが決して発せられないので、db.event.insertメソッドが見逃されるので、データを挿入することからも同じことが言えます。私はテストから、console.logsを使用して見つけました。

私は、DHTMLX Schedulerチュートリアル、Webサイトのドキュメント、MongoDBドキュメント、MongoSkinドキュメントを読みました。私は完全な解決策を完全に見逃す可能性がありますが、私はここで何が欠けているかを見つけることができないので、どんな助けにも感謝します。ありがとう。

答えて

0

しかし、私はdb.event.insert()の動作を開始できませんでした。なぜなら、そのルートは起動していないからです。

あなたのコードは、あなたが/更新を挿入すると/クライアント側で項目を削除すると呼ばれているPOST /データ要求のためのルートを持っていないように思えます。ここでGET/initをルートについてサンプルhttps://github.com/DHTMLX/node-scheduler-demo/blob/master/app.js#L52

の関連コードがある - 唯一のDBにいくつかのテストデータを挿入するために使用されます、そして手動で呼ばれています。あなたはそれをアプリケーションの他の部分に影響を与えずに削除することができます

+0

お返事ありがとうございます。 私は以前にこの投稿データを持っていましたが、テストデータを取得できなかったため、この質問には除外されていました。 投稿を元に戻しても結果は変わりません。私はgithub repoを参考にしました。私が間違っていたことはまだ分かりません。 – Coffeeteer

関連する問題