Javascript Ext.data.Store中的可用时间段?
我不熟悉JavaScript和Sencha,但熟悉as3/flex。我在as3中构建了类似的东西,但我很难将其转移到Sencha JS中。Javascript Ext.data.Store中的可用时间段?,javascript,extjs,Javascript,Extjs,我不熟悉JavaScript和Sencha,但熟悉as3/flex。我在as3中构建了类似的东西,但我很难将其转移到Sencha JS中。 我有一个Ext.data.Store。此Ext.data.Store将根据选定日期的计划时间段而更改。我需要能够根据这些参数提取可用的2小时时间块 开始时间和结束时间以15分钟为增量,长度应始终为2小时。虽然Ext.data.Store中的一些计划时间可能大于2小时,或者小于2小时,但我仍然需要能够将2小时的时间段显示为空闲时间。在Ext.data.Stor
我有一个Ext.data.Store。此Ext.data.Store将根据选定日期的计划时间段而更改。我需要能够根据这些参数提取可用的2小时时间块 开始时间和结束时间以15分钟为增量,长度应始终为2小时。虽然Ext.data.Store中的一些计划时间可能大于2小时,或者小于2小时,但我仍然需要能够将2小时的时间段显示为空闲时间。在Ext.data.Store中可能会看到重复的时间段被填满,因为计划中有多个人。我在考虑按员工设置某种循环,因此如果员工计数为3,它将循环代码3次,以找到可用的2小时时间段
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));
}
}
}*/
});
我能看见这些物体
对象
雇员:“詹姆斯”
结束时间:“10:00”
时间:“8:00”
原型:对象
但我不知道如何实现按员工对所有时间段进行排序,然后找到每个员工时间段之间的所有两个小时间隔
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));
}
}
}*/
});
Ext.onReady(函数()
{
console.log('ready!');
变量常数={
“工作日开始”:“08:00”,
“工作日结束”:“18:00”,
“间隔小时数”:2
};
Ext.define('Times'{
扩展:“Ext.data.Model”,
字段:[
{name:'stime',键入:'string'},
{name:'endtime',键入:'string'},
{name:'employee',type:'string'}
]
})
Ext.create('Ext.data.Store'{
storeId:'ac',
模型:“时代”,
数据:[
{时间:“8:00”,结束时间:“10:00”,员工:“詹姆斯”},
{时间:“13:00”,结束时间:“15:00”,员工:“詹姆斯”},
{时间:“15:00”,结束时间:“17:30”,员工:“詹姆斯”},
{时间:“12:00”,结束时间:“14:00”,员工:“卡尔”},
{时间:“14:00”,结束时间:“16:00”,员工:“卡尔”},
{时间:“14:00”,结束时间:“16:00”,员工:“吉米”}
]
});
函数addZero(num){
//创建一个数组,如果字符串是“xx:xx”格式,数组将是[“xx”,“xx”],否则它将是[“xx”]
var i=新的数字();
var arr=String(num).indexOf(“:”)==-1?[num]:String(num).split(“:”);
对于(i=0;i=常数。间隔时间\u小时数;hourInterval+=常数。间隔时间\u小时数){
//跟踪可用的时间段
跟踪(employeeName,“=”,addZero((endDate.hours+hourInterval)+“:”+endDate.minutes),
“to”,addZero((endDate.hours+hourInterval+constants.INTERVAL\u HOUR\u 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'
}
]);
那么你的问题是什么?