簡體   English   中英

來自Ext.data.Store的可用時隙?

[英]Available Time Slots From a Ext.data.Store?

我是JavaScript和Sencha的新手,但熟悉as3 / flex。 我在as3中構建了與此類似的東西,但是我很難將其移至Sencha JS。
我有一個Ext.data.Store。 該Ext.data.Store將根據所選日期的預定時間段而變化。 我需要能夠根據這些參數提取2小時的可用時間塊。

開始時間和結束時間以15分鍾為增量,並且應始終為2小時。 盡管Ext.data.Store中的某些計划時間可能大於2小時,或更短的時間,我仍然需要能夠將2小時時隙顯示為空閑時間。 在Ext.data.Store中可能會看到重復的時隙已滿,因為時間表中有不止一個人。 我當時正在考慮按員工設置某種循環,因此,如果員工人數為3,它將遍歷代碼3次,以找到可用的2小時時隙。

我能夠看到對象Object員工:“ james”結束時間:“ 10:00” stime:“ 8:00” proto :對象

但我不知道如何按員工對所有時間段進行排序,然后找到每個員工的時間段之間的所有兩個小時間隔。

Ext.onReady(function()
{
console.log('ready!');

var constants = {
'WORKDAY_START': '08:00',
'WORKDAY_END': '18:00',
'INTERVAL_HOUR_COUNT': 2
};
Ext.define('Times', {
    extend: 'Ext.data.Model',
    fields:[
            {name: 'stime', type: 'string'},
            {name: 'endtime', type: 'string'},
            {name: 'employee', type: 'string'}
            ]
 })



 Ext.create('Ext.data.Store', {
 storeId: 'ac',
 model: 'Times',
 data : [
     {stime:"8:00", endtime:"10:00", employee:"james"},              
     {stime:"13:00", endtime:"15:00", employee:"james"},
     {stime:"15:00", endtime:"17:30", employee:"james"},
     {stime:"12:00", endtime:"14:00", employee:"carl"},               
     {stime:"14:00", endtime:"16:00", employee:"carl"},
     {stime:"14:00", endtime:"16:00", employee:"jimmy"}
 ]
 });



 function addZero(num) {
            // Create an array, if string is in "xx:xx" format, the array       will be ["xx", "xx"], otherwise it will be ["xx"]
            var i = new Number();
            var arr = String(num).indexOf(":") == -1 ? [num] :   String(num).split(":");
            for (i = 0; i < arr.length; i++) // Add an "0" if the string   is only one character
            if (arr.length == 1){
             arr[i] = "0" + arr[i];
                }
            return arr.join(":");
        }







 var ac = Ext.data.StoreManager.lookup('ac').data;

 var employeeTimeSlots = new Array();
 ac.each(function(item, index, allItems) {

//console.log("a[" +arrayItem+ "] = " + index);
console.info(item.data);

//console.log('@ready');    
            var timeSlot = new Array();

            for (timeSlot in item.data) {

                  var employeeSlots = new Array();
                var employee = timeSlot.employee;
                if (!employeeSlots['employee'])   employeeSlots['employee'] = [];
                employeeSlots.push(['employee'],{
                    stime: timeSlot.stime,
                    endtime: timeSlot.endtime

                });
                //console.log(employeeSlots)
                //console.log(timeSlot);
            }

// Second step, find all two hour intervals between each employee's time slot

            /*for (var employee in employeeSlots) {
                var   employeeTimeSlots=Array(employeeSlots['employee']);
                // Add in the first and last time stamps
                employeeTimeSlots.unshift({endtime:   constants.WORKDAY_START});
                employeeTimeSlots.push({starttime: constants.WORKDAY_END});
                // Find all the time differences
                for (var i = 0; i < employeeTimeSlots.length-1; i++) {
                    // The end hours of the current time slot


                    var endDate = new Date(0, 0, 0,   employeeTimeSlots[i].endtime.substring(0, 2),
                        employeeTimeSlots[i].endtime.substring(3, 2), 0, 0);
                    // The beginning hours of the next time slot
                    var nextStartDate = new Date(0, 0, 0, employeeTimeSlots[i+1].starttime.substring(0, 2),
                        employeeTimeSlots[i+1].starttime.substring(3, 2), 0, 0);
                    // The hours in between the time slots
                    var availableHours = Number((nextStartDate.getTime() - endDate.getTime())) / (1000 * 60 * 60);
                    // For every two hours that are available between these time slots
                    for (var hourInterval = 0; availableHours -   hourInterval >= constants.INTERVAL_HOUR_COUNT; hourInterval += constants.INTERVAL_HOUR_COUNT)   {
                        // Trace the available time slot
                        trace(employeeName, "=", addZero((endDate.hours + hourInterval) + ":" + endDate.minutes), 
                            "to", addZero((endDate.hours + hourInterval + constants.INTERVAL_HOUR_COUNT) + ":" + endDate.minutes));
                    }

            }
                    }*/




 });

您可以按一個字段或多個字段對商店排序。

如果您的商店名為mystore,您將擁有

mystore.sort('employee','ASC')

根據文檔,我們有:

//sort by a single field
myStore.sort('myField', 'DESC');

//sorting by multiple fields
myStore.sort([
{
    property : 'age',
    direction: 'ASC'
    },
    {
        property : 'name',
        direction: 'DESC'
    }
]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM