从远程服务器获取日历事件的数据

时间:2012-03-01 07:35:16

标签: sencha-touch

我创建了一个商店:

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();
    });
});

但是数据没有从第一家商店转移到第二家商店。

如何将数据传输到第二家商店?或者有没有办法以其他方式将第一家商店的数据提供给日历?

1 个答案:

答案 0 :(得分:0)

迟到总比没有好。要回答您的问题,您可以使用HTTP缓存并在第二个商店的init函数中加载商店。因为它已被缓存,所以没有网络传输就可以获得数据。