我如何在jquery中获得预约时间(从时间到时间) [英] How i get appointment time (From time,To time) in jquery

查看:208
本文介绍了我如何在jquery中获得预约时间(从时间到时间)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在拖动时隙单元格时选择时隙。选择时段后,我在文本框中输入患者姓名,然后单击选择按钮,然后患者姓名进入选定的时间段。用户可以选择多个时间段用于多个患者姓名和按钮分配按钮我必须将带有时间段(从时间到时间)的患者姓名插入到数据库中。

I am selecting time slot on dragging on time slot cell. After selecting time slot, I enter patient name in textbox and click on select button then patient name goes to selected time slot. The user can select multiple time slot for multilpe patient name and onclick of allot button I have to insert patient name with time slot (From time To time) to database.

我在获取分配时段时遇到问题ie.From time and To time in jquery。

I have problem in getting alloted time slot ie.From time and To time in jquery.

$("#btnAllot").click(function () {
    //how i get alloted time here.
    $('tr').each(function () {
        $(this).find('td').each(function () {
            if ($(this).hasClass('yell')) {
                alert($(this).closest('tr').find('td:eq(0)').text());

            };
        });
    });
}

在时间段单元格上拖动时查看jsbin

推荐答案

好的,这是一种方法:

你迭代第三个单元格有 rowspan 的每一行这表示新约会的开始。你可以通过获取 rowspan的行来检查兄弟姐妹(的种类)和结束时间来获得开始时间。 1 元素消失。

You iterate over each row whose third cell has a rowspan attribute. This indicates the start of a new appointment. You can get the start time by examining the siblings (sort of) and the end time by getting the row that is rowspan - 1 elements away.

可能有更好的方法,但这可能会给你一个开始。

There might be better ways, but this might give you a start.

例如:

var find_closest_hour = function($row) {
    var $cell = $row.children('td:first-child'),
        hour = "";
    // probably add something here
    while($cell.length && !(hour = $.trim($cell.text()))) {
        $cell = $cell.parent().prev().children('td:first-child');
    }
    return hour;
};

var $all_tds = $('#tableAppointment tr td:nth-child(3)'),
    $tds = $all_tds.filter('[rowspan]'); 

// will contain a list of objects [{patient: name, start: time, end: time},...]
var appointments = $tds.map(function() {
    var $this = $(this),
        $row = $this.parent(),
        $cells =  $row.children('td'),
        patient = $.trim($this.text()),
        start = find_closest_hour($row).split(':', 1) + ":" + $.trim($cells.eq(1).text()),
        $end_row, end;

    if(this.rowspan == 1) {
        end = start;
    }
    else {
        $end_row = $all_tds.eq($all_tds.index(this) + this.rowSpan - 1).parent();
        end = find_closest_hour($end_row).split(':', 1) + ":" + $.trim($end_row.children('td').eq(1).text());
    }

    return {patient: patient, start: start, end: end};
}).get();

DEMO

我会让你弄清楚如何正确格式化时间;)

I will let you figure out how to format the times properly ;)

注意:这在很大程度上取决于您当前的表结构,如果您更改它可能会中断。为了使事情更灵活,您可以将类添加到包含重要信息的单元格,例如小时到包含当天小时的每个第一个单元格和 appointment_start 到约会的单元格。然后你可以搜索/过滤这些。

Note: This very much depends on your current table structure and is likely to break if you change it. To make things more flexible, you could add classes to cells that contain the important information, for example hour to each first cell that contains the hour of the day and appointment_start to the cell of an appointment. Then you could search for/filter by these.

这篇关于我如何在jquery中获得预约时间(从时间到时间)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆