2012-03-01 137 views
0

我創建了一個店的日曆事件:從遠程服務器數據

Ext.regStore('EventCalendarStore',{ 
model: 'EventCalendar', 
proxy:{ 
    type:'ajax', 
    url:url, 
    reader:{ 
     type:'json' 
    } 
}, 
    autoLoad:true 
}); 

EventsApp.stores.eventCalendarStore = Ext.StoreMgr.get('EventCalendarStore'); 

它以JSON格式存儲數據。

我正在使用Ext.ux.TouchCalendarView日曆,並且此日曆以不同於我創建的商店結構的方式接收數據。

var eventStore = new Ext.data.Store({ 
    model: 'Event', 
    data: [{ 
     event: 'Breaking Development 2011', 
     location: 'Nashville', 
     start: new Date(2011, 8, 12), 
     end: new Date(2011, 8, 14) 
    }, { 
     event: 'TechCrunch Disrupt SF', 
     location: 'San Francisco', 
     start: new Date(2011, 8, 12), 
     end: new Date(2011, 8, 14) 
    }, { 
     event: 'ATypl Reykjavik 2011', 
     location: 'Reykjavik', 
     start: new Date(2011, 8, 14), 
     end: new Date(2011, 8, 18) 
    }, { 
     event: 'Do Wales 2011', 
     location: 'Cardigan', 
     start: new Date(2011, 8, 14), 
     end: new Date(2011, 8, 18) 
    }, { 
     event: 'Future of Mobile', 
     location: 'London', 
     start: new Date(2011, 8, 16), 
     end: new Date(2011, 8, 16) 
    }, { 
     event: 'WindyCityRails 2011', 
     location: 'Chicago', 
     start: new Date(2011, 8, 17), 
     end: new Date(2011, 8, 17) 
    }, { 
     event: 'CapitoUS', 
     location: 'Washington DC', 
     start: new Date(2011, 8, 18), 
     end: new Date(2011, 8, 18) 
    }, { 
     event: 'Strange Loop 2011', 
     location: 'St Louis', 
     start: new Date(2011, 8, 18), 
     end: new Date(2011, 8, 20) 
    }, { 
     event: 'Frozen Rails 2011', 
     location: 'Helsinki', 
     start: new Date(2011, 8, 20), 
     end: new Date(2011, 8, 21) 
    }, { 
     event: 'Web Accessibility', 
     location: 'London', 
     start: new Date(2011, 8, 21), 
     end: new Date(2011, 8, 21) 
    }, { 
     event: 'onGameStart', 
     location: 'Warsaw', 
     start: new Date(2011, 8, 22), 
     end: new Date(2011, 8, 23) 
    }, { 
     event: 'Improving Reality', 
     location: 'Brighton', 
     start: new Date(2011, 8, 23), 
     end: new Date(2011, 8, 23) 
    }, { 
     event: 'Android Homecoming', 
     location: 'Mountain View', 
     start: new Date(2011, 8, 23), 
     end: new Date(2011, 8, 25) 
    }, { 
     event: 'Mobilize', 
     location: 'San Francisco', 
     start: new Date(2011, 8, 26), 
     end: new Date(2011, 8, 27) 
    }, { 
     event: 'Accessibility Summit', 
     location: 'Online', 
     start: new Date(2011, 8, 27), 
     end: new Date(2011, 8, 27) 
    }, { 
     event: 'UX Web Summit', 
     location: 'Online', 
     start: new Date(2011, 8, 28), 
     end: new Date(2011, 8, 28) 
    }, { 
     event: 'Modernizer with Faruk Ates', 
     location: 'San Francisco', 
     start: new Date(2011, 8, 29), 
     end: new Date(2011, 8, 29) 
    }, { 
     event: 'Creative JavaScript and HTML5', 
     location: 'Brighton', 
     start: new Date(2011, 8, 29), 
     end: new Date(2011, 8, 30) 
    }, { 
     event: 'UX Camp Brighton', 
     location: 'Brighton', 
     start: new Date(2011, 9, 1), 
     end: new Date(2011, 9, 1) 
    }, { 
     event: 'Future of Web Apps', 
     location: 'London', 
     start: new Date(2011, 9, 3), 
     end: new Date(2011, 9, 5) 
    }, { 
     event: 'droidcon 2011', 
     location: 'London', 
     start: new Date(2011, 9, 6), 
     end: new Date(2011, 9, 7) 
    }, { 
     event: 'PHP NW 2011', 
     location: 'Manchester', 
     start: new Date(2011, 9, 7), 
     end: new Date(2011, 9, 9) 
    }, { 
     event: 'O\'Reilly Android Open Conference', 
     location: 'San Francisco', 
     start: new Date(2011, 9, 9), 
     end: new Date(2011, 9, 11) 
    }, { 
     event: 'Web 2.0 Expo/NY', 
     location: 'New York', 
     start: new Date(2011, 9, 10), 
     end: new Date(2011, 9, 13) 
    }, { 
     event: 'Sencha Con', 
     location: 'Austin, Texas', 
     start: new Date(2011, 9, 23), 
     end: new Date(2011, 9, 26) 
    }, { 
     event: 'Future of Web Design', 
     location: 'New York', 
     start: new Date(2011, 10, 7), 
     end: new Date(2011, 10, 9) 
    }, { 
     event: 'Build', 
     location: 'Belfast', 
     start: new Date(2011, 10, 7), 
     end: new Date(2011, 10, 11) 
    }, { 
     event: 'Heart & Sole', 
     location: 'Portsmouth', 
     start: new Date(2011, 10, 18), 
     end: new Date(2011, 10, 18) 
    }] 
}); 

這就是爲什麼我必須爲此日曆創建另一個商店,並以正確的方式呈現格式。我正在以這種方式重新創建商店:

EventsApp.stores.eventCalendarStore.load(function(){ 
    EventsApp.stores.eventCalendarStore.each(function(record){ 

     var dateS = record.data.startTime; 
     var dateE = record.data.endTime; 

     var converterEndTime = new Date(); 
     var converterStartTime = new Date(); 
     var startT = new Object(); 
     var endT = new Object(); 

     if(typeof dateS =='string') { 
      converterStartTime = new Date(dateS.substr(0,10)*1000); 

     }else { 
      converterStartTime = new Date(dateS); 
     } 


     if(typeof dateE =='string'){ 
      converterEndTime = new Date(dateE.substr(0,10)*1000); 
     }else{ 
      converterEndTime = new Date(dateE); 
     } 
     endT = converterEndTime.format("Y , n, j"); 
     startT = converterStartTime.format("Y , n, j"); 
     var cStore = EventsApp.stores.eventCalendarOfflineStore; 
     cStore.add({ 
      event:record.data.name, 
      location:record.data.notes, 
      start:new Date(startT), 
      end:new Date(endT) 
     }); 
     cStore.sync(); 
     record.save(); 
    }); 
}); 

但是,數據並未從第一個存儲轉移到第2個存儲。

如何將數據傳輸到第二家商店?或者有什麼方法可以將數據從第一家商店以其他方式提供給日曆?

回答

0

比從未更好的遲到。要回答您的問題,您可以使用HTTP緩存並將商店加載到第二商店的init函數中。因爲它已被緩存,所以沒有網絡傳輸的數據就在那裏。

相關問題