2017-12-19 11 views
1

나는 fullcalendar 패키지를 사용하고 있습니다. 내 목표는 달력에서 데이터베이스의 약속을 표시하는 것입니다.날짜를 다른 형식으로 fullcalendar로 표시하는 방법은 무엇입니까?

문서에서 나는 events() 함수를 사용해야합니다.

내 모음집 (Requests)은 제목과 시작 속성이 있습니다. 내가 여기 순간에 붙어

start: 'December 19, 2017 at 9:43 PM' 

: 다음과 같이 시작 속성은 저장

Template.appointments.onRendered(() => { 
    $('#calendar').fullCalendar({ 
    events(start, end, timezone, callback) { 


     }); 
    } 
    }); 
}); 

가 어떻게 날짜와 시간을 검색하고 달력에 표시 가야한다 ?

는 UPDATE : 여기

내가 시도 것입니다 :

를 : 그것은 작동하지 않았다

Template.appointments.onRendered(() => { 
    $('#calendar').fullCalendar({ 
    events(start, end, timezone, callback) { 
     let data = Requests.find().fetch().map((event) => { 
      event.start = new Date(event.start.replace("at", "")); 
      event.end = new Date(event.start.replace("at", "")); 
      return event; 
     }); 

     if (data) { 
      callback(data); 
     } 
    } 
}); 

    Tracker.autorun(() => { 
    Requests.find().fetch(); 
    $('#calendar').fullCalendar('refetchEvents'); 
}); 

}); 

, 나는 events 함수 내에서 모든 코드를 제거하고 다음에 변경 시도

Template.appointments.onRendered(() => { 
    $('#calendar').fullCalendar({ 
    events(start, end, timezone, callback) { 
     console.log('WORKS!') 
    } 
}); 
}); 

아무 것도 콘솔에 인쇄되지 않았습니다. 이벤트 내부의 코드가 실행되지 않는 이유는 무엇입니까?

참고 : 일정은 성공적으로 서식 파일에로드되었지만 비어 있습니다.

+0

fullcalendar 유성에 아주 좋은 상세한 튜토리얼이있다? OR는 datetime 객체입니다. – blueren

+0

@blueren – sourceplaze

+0

문자열을 데이터베이스에 문자열로 저장하지 않습니다. 그것은 끔찍한 생각입니다. 심지어 쿼리를 작성할 수도 없습니다. _GUI_는 날짜 형식을 지정해야합니다 (일반적으로 사용자의 로컬 사용자 정의 또는 ISO와 같은 명확하지 않은 형식에 따라 수행해야합니다). 코드의 다른 모든 곳에서 프로그래밍 언어로 적합한 DateTime 유형의 개체를 사용해야합니다. – ADyson

답변

1

현재 날짜를 문자열로 저장하고 있습니다.

var start_date = new Date(start.replace("at", "")); 

위의 것은 당신에게 동일한 날짜 객체를 가져옵니다. 문자열에서 "at"을 제거하면 Date 생성자로 전달되는 동안 오류가 발생합니다.

귀하의 템플릿과는 비슷해야 기능을 렌더링입니다 : 내 지역에서 위의 테스트

Template.appointments.onRendered(function() { 

    // each time a reactive entity changes, whatever is inside tracker.autorun is run again. 
    Tracker.autorun(function() { 


     var eventsArray = []; 
     // events.find() is reactive. Any change to the events collection will trigger the autorun to run. 
     events.find().forEach(function(event) { 
      eventsArray.push({ 
       title: event.title, 
       start: event.startDate, //should be preferably in ISO format 
       end: event.endDate //should be preferably in ISO format 
      }); 

     }); 

     // Each time some data changes, fullCalendar must be notified again. 
    $('#calendar').fullCalendar('removeEvents'); 
    $('#calendar').fullCalendar(eventsArray); 
    $("#calendar").fullCalendar('addEventSource', eventsArray); 
    $("#calendar").fullCalendar('rerenderEvents'); 
    }); 
}); 

<template name ="appointments"> 
    .... 
    .... 
    <div id = "calendar"></div> 
    .... 
    .... 
</template> 

template.js

template.html 테스트 애플 리케이션 및 작동합니다.

enter image description here , 당신은 날짜를 저장하는 문자열을 사용하는 보조 노트에 here

+0

명확한 답변에 감사드립니다. 나는 하나의 질문을 가지고 있는데, 나는 'Requests.find()'를 사용하여 이벤트 컬렉션을 가져오고있다. 루프를 사용해야 할까? 아니면 더 나은 연습이 있습니까? – sourceplaze

+0

자세한 내용을 모른 채 말하기가 어렵습니다. 일반적인 접근 방식은 반복 할 수있는 커서를 반환하기 때문에 find를 사용하는 것입니다. – blueren

+0

console.log()로 테스트 한 후에도 이벤트 함수가 작동하지 않습니다. 나는 질문을 업데이트했다. 이유를 아는 지 확인해 주시겠습니까? – sourceplaze

관련 문제