2014-12-03 63 views
0

具體事件我有一個JSON飼料全部數據的下頁:如何顯示從JSON飼料

'./PlanningFeed.xhtml' 

我可以給一個基本的使用fullcalendar數據,並將其工作。

問題是我想只顯示滿足條件的事件。

這是我得到的JSON數據:

eventSources: [ 
     { 
      url: './PlanningFeed.xhtml', 
      type: 'GET', 
      data: { 
       start: firstdate, 
       end: lastdate, 
       salle: salle //this is my attempt to get only events that has a specific 
          //"salle" attribute,the field salle is declared and populated 
          //in all event objects. 
          //but this parameter here it doesn't affect 
          //anything and my calendar is created with all salle events showed. 
          //which means this doesn't work. 
      } 
     } 
    ] 
}); 

此外,我嘗試了eventRender卻無濟於事:

eventRender: function(event, element) { 


     if (event.salle === salle) { 
      console.log('added', event.salle); 

     } else if (event.salle !== salle) { 
      console.log('deleted', event.salle); 
      $(placeholder).fullCalendar('removeEvents', event.id); 

     } 
    } 

我不想從JSON提要我可以刪除數據稍後使用它。我希望如果我能查詢JSON提要只顯示我想要的事件(例如:event.salle ='XYZ')。

請不要猶豫,詢問更多信息。

更新1:

[{"title":"uiyuiyutyiyuity\nANGIO SCANNER RENALE.","start":"2014-12-01T07:30:00","end":"2014-12-01T07:45:00","salle":"SCANNER1","backgroundColor":"#B6E8FF","patState":4,"rapportWrittenState":0,"patientFullName":"uiyuiyutyiyuity","studyDureeMinute":15,"payStateImage":"non-cote","bannerColor":"#98d1ec","borderColor":"#98d1ec","id":"1"}, 
{"title":"hjghjghjghj\n2 CHEVILLE F","start":"2014-12-01T07:15:00","end":"2014-12-01T07:35:00","salle":"RADIO 1","backgroundColor":"#CDDFED","patState":1,"rapportWrittenState":0,"patientFullName":"hjghjghjghj","studyDureeMinute":20,"payStateImage":"non-cote","bannerColor":"#a0c2dc","borderColor":"#a0c2dc","id":"2"}, 
{"title":"yiyuiyuiyui\nANGIO SCANNER ABDOMINALE.","start":"2014-12-01T06:55:00","end":"2014-12-01T07:15:00","salle":"SCANNER1","backgroundColor":"#F0F0F0","patState":7,"rapportWrittenState":0,"patientFullName":"yiyuiyuiyui","studyDureeMinute":20,"payStateImage":"non-cote","bannerColor":"#C8C8C8","borderColor":"#C8C8C8","id":"3"}, 
{"title":"tuutyuj\nANGIO SCANNER CEREBRAL.","start":"2014-12-01T06:25:00","end":"2014-12-01T06:45:00","salle":"SCANNER1","backgroundColor":"#E8F5BB","patState":5,"rapportWrittenState":0,"patientFullName":"tuutyuj","studyDureeMinute":20,"payStateImage":"non-cote","bannerColor":"#cede97","borderColor":"#cede97","id":"4"}, 
{"title":"dfgdfgdfgdfg\nANGIO SCANNER CERVICAL.","start":"2014-12-01T06:00:00","end":"2014-12-01T06:20:00","salle":"SCANNER1","backgroundColor":"#FFC592","patState":3,"rapportWrittenState":0,"patientFullName":"dfgdfgdfgdfg","studyDureeMinute":20,"payStateImage":"c_valider","bannerColor":"#e8a66c","borderColor":"#e8a66c","id":"5"}] 
+0

你可以顯示你的json返回的示例代碼嗎? – Kristiyan 2014-12-03 11:58:12

+0

肯定會看到更新1. – 2014-12-03 11:59:36

+0

,而不是要求完整的日曆來觸發ajax,你不能只發送請求,獲取數據,過濾數據,將它保存在一個數組中,並將其作爲完整日曆的輸入? – 2014-12-03 12:10:58

回答

0

通過使用JSF完成ajax oncomplete,從服務器端調用fullcalendar完成。

  1. 從數據庫加載特定數據。
  2. 使用GSON將其轉換爲JSON字符串。
  3. 將事件數組加載到日曆。

希望這會有所幫助。

1

我沒有完整的日曆很好,但是我發現你的問題

解決方案刪除事件後,必須重新呈現所有事件:

$(placeholder).fullCalendar('removeEvents', event.id); 
setTimeout(function(){ 
$(placeholder).fullCalendar("rerenderEvents"); 
},1); 

我確實使用超時。它正在測試fullcalendar-2.2.3新鮮下載。編輯: 請確保您的變量和條件。

+0

它現在工作,但我看到所有的事件,然後我看不到消失的事件。 – 2014-12-03 13:40:45

+0

,但沒有更好的解決方案,像只提取我需要的數據? – 2014-12-03 13:53:41

0
var eventStore;// store pre filtered events here so we can get at them later 
... 
events: function(start,end,callback) { 
    $.ajax('http://www.myendpoint.com/getevents.php', {start:start,end:end}, function(data) { 
     var events = JSON.parse(data); 
     eventStore = events; 
     var newEventList = []; 
     for(var i = 0; i < events.length; i++){ 
      if(events.salle == true){ 
       newEventList.push(events[i]); 
      } 
     } 
     callback(newEventList); 
    }); 
} 

這可能是最有意義的有你的Web服務來過濾數據並返回你所需要的,但你可以過濾使用上述自定義函數來顯示之前的事件。