最近使用dhtmlx的scheduler来做一个插件.
觉得这个东东确实是非常好用的.
这里我主要说明一下如何使用json来作为scheduler的数据源.默认情况下是使用xml来做数据源的,之前我也是用xml但是发现数据的实时性还是会存在问题.而且在生成xml中也容易出问题.
1.先来看看基本配置吧.
- <script type="text/javascript" charset="utf-8">
- $(function(){
- scheduler.config.prevent_cache = false;
- scheduler.config.lightbox.sections=[
- {name:"description", height:70, map_to:"text", type:"textarea" , focus:true},
- {name:"time", height:72, type:"time", map_to:"auto"}
- ]
- scheduler.config.first_hour=7;
- scheduler.config.time_step=30;
- scheduler.config.api_date="%Y-%m-%d %H:%i";
- scheduler.config.xml_date="%Y-%m-%d %H:%i";
- scheduler.config.hour_date="%H:%i";
- scheduler.config.default_date="%Y年%m月%d日";
- scheduler.config.month_date="%Y年 %m月";
- scheduler.config.day_date="%D %m月%d日";
- scheduler.config.start_on_monday=true;
- scheduler.config.details_on_create=true;
- scheduler.config.details_on_dblclick=true;
- scheduler.init('scheduler_here',new Date(<?php echo $now->format('Y') ?>,<?php echo $now->format('m') - 1 ?>,<?php echo $now->format('d') ?>),"week");
- var convert = scheduler.date.date_to_str("%Y-%m-%d %H:%i:%s");
- var dateConvert = scheduler.date.date_to_str('%Y-%m-%d');
- var equipment_number = <?php echo $equipment_number; ?>;
- //载入文件
- scheduler.load("/lms/lmsReg/generateEquipmentRegInfoJson?equipment_number="+equipment_number,"json");
- //以下代码为绑定事件:条目变化(拖拉事件、调整时间)
- scheduler.attachEvent("onEventChanged", function(event_id,event_object){
- });
- //以下代码为绑定事件:增加
- scheduler.attachEvent("onEventAdded", function(event_id,event_object){
- var startdate = convert(event_object.start_date);
- var enddate = convert(event_object.end_date);
- var title = event_object.text;
- var date = dateConvert(event_object.end_date);
- var equipment_number = <?php echo $equipment_number; ?>;
- $.post('ajaxReturnNextRegStamp',function(regstamp){
- $.post('regEquipmentCreate',{equipment_number: equipment_number,starttime: startdate,endtime: enddate,date: date,title: title,regstamp:regstamp},function(data){
- if(data == 'success') {
- $.messager.show({
- title: '消息',
- msg: "<span style='font-size: 14px'>设备预约成功!</span>",
- showType: 'fade',
- timeout: 2000
- });
- setTimeout(window.location.reload,3000);
- scheduler.addEvent(startdate,enddate,title,event_id);
- }
- if(data == 'error'){
- $.messager.alert('错误','时间冲突','error');
- scheduler.deleteEvent(event_id);
- }
- if(data != "success" && data != "error"){
- $.messager.alert('错误','抱歉!您的预约没有成功!<br>错误原因: '+data+'','error');
- scheduler.deleteEvent(event_id);
- }
- });
- });
- });
- scheduler.attachEvent('onEventDeleted',function(event_id,event_object){
- var equipment_number = <?php echo $equipment_number; ?>;
- $.post('delReg',{regstamp: event_id});
- });
- })
- </script>
2.载入json
- //载入文件
- scheduler.load("/lms/lmsReg/generateEquipmentRegInfoJson?equipment_number="+equipment_number,"json");
注意最后面要定义为json格式.
3.json的格式:
- [
- {"id":"1","start_date":"2012-09-28 08:30:00","end_date":"2012-09-28 13:30:00","text":"\u7533\u8bf7\u4eba: \u8d85\u7ea7\u7ba1\u7406\u5458
- \u7533\u8bf7\u5185\u5bb9: \u65b0\u9884\u7ea6","details":"admin"}
- ]
本文出自 “难道是神仙” 博客,请务必保留此出处http://leexiaobo.blog.51cto.com/2851883/1006370