dojox.calendar和JsonRest - 如何更新? [英] dojox.calendar and JsonRest - how to update?

查看:136
本文介绍了dojox.calendar和JsonRest - 如何更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手,所以请忍受我。我正在努力创建一个dojo日历,其中包含来自数据库的事件。日历默认为网格(月度)视图,并且在加载时,进行初始调用以获取第一组事件。默认视图进行呼叫以获得当前月份事件+/-一周。我在Observable中使用JsonRest对象来完成此操作。

I'm very new to dojo, so please bear with me. I'm currently working on creating a dojo calendar, with events sourced from a database. The calendar defaults to the grid (monthly) view, and on load, makes an initial call to get the first set of events. The default view makes a call to get the current months events +/- one week. I'm using a JsonRest object in an Observable to accomplish this.

目前这个工作没有问题。我在发生问题的地方是拉/更新其他月份的数据。期望的效果是让用户点击前进或后退按钮移动到下一个或上一个月。发生这种情况时,我想向数据库查询要显示的新事件。我可以返回新的数据并登录到控制台,但我无法在日历上显示。我确定我错过了一些(希望)简单的东西,但是我不能弄清楚,或找到任何好的文档。这是我有的:

This is currently working without issue. Where I'm having an issue is pulling / updating data for other months. The desired effect is to have the user click the forward or back button to move to the next or previous month. When this occurs, I would like to query the database for the new events to display. I'm able to return the new data and log it to the console, but I cannot get it to display on the calendar. I'm sure I'm missing something (hopefully) simple, but I cant figure it out, or find any good documentation. Here's what I have:

require(['dojo/parser', 
         'dojo/ready',
         'dojox/calendar/Calendar',
         'dojo/store/Observable',
         'dojo/store/JsonRest',
         'dijit/registry'],
  function(parser, ready, Calendar, Observable, JsonRest, registry) {
    ready(function(){
        var MM   = new Date().getMonth() + 1;
        if (MM < 10)
          { MM = '0' + MM};

        var YYYY = new Date().getFullYear();
        var monthStore  = new Observable(JsonRest({target: '/levelx/teamSchedule/getMonthInfo/'}));
        calendar = new Calendar({
          store: monthStore,
          dateInterval: 'month',
          style: styleText,
          editable: false,
          cssClassFunc: function(e){
            return e.calendar;
          },
          query: '?q=' + YYYY + '-' + MM
        }, 'calendar');

    calendar.on("timeIntervalChange",function(e){
      var YYYY = e.startTime.getFullYear();
      var MM   = e.startTime.getMonth() + 1;
      if (MM < 10)
        { MM = '0' + MM};
      monthStore.query('?q=' + YYYY + '-' + MM).then(function(results){
        console.log(results);
      });
    });

我觉得我很亲密。像我说的,我有正确的数据被返回到控制台(console.log(结果)),但没有线索如何让它显示在实际的日历。

I feel like I'm so close. Like I said, I have the correct data being returned to the console (console.log(results)), but no clue how to get it to show in the actual calendar.

推荐答案

我能够通过以下修改完成我需要的。每当用户更改显示的日期范围时,它将自动运行查询以收集和显示正确的事件。

I was able to accomplish what I needed with the following modifications. Whenever the user changes the displayed date range, it will automatically run a query to gather and display the proper events.

require(['dojo/parser',
         'dojo/ready',
         'dojox/calendar/Calendar',
         'dojo/store/JsonRest',
         'dijit/registry',
         'dojo/dom',
         'dojo/html'],
  function(parser, ready, Calendar, JsonRest, registry, dom, html) {
    ready(function(){
        var MM   = new Date().getMonth() + 1;
        if (MM < 10)
          { MM = '0' + MM};
        var YYYY = new Date().getFullYear();
        var detailStore = JsonRest({target: '/levelx/teamSchedule/getDayInfo/'});
        var monthStore  = JsonRest({target: '/levelx/teamSchedule/getMonthInfo/'});

        calendar = new Calendar({
          dateInterval: 'month',
          style: styleText,
          editable: false,
          cssClassFunc: function(e){
            return e.calendar;
          }
        }, 'calendar');

        calendar.on("timeIntervalChange",function(e){
          var YYYY = e.startTime.getFullYear();
          var MM   = e.startTime.getMonth() + 1;
          if (MM < 10)
            { MM = '0' + MM};

          calendar.set('query','?q=' + YYYY + '-' + MM);
          calendar.set('store', monthStore);
        });
    });
});

这篇关于dojox.calendar和JsonRest - 如何更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆