简体   繁体   English

具有多个继承级别的表-JQuery

[英]Table with multiple levels of inheritance - JQuery

I have a project class and the inheritance goes Projects have Sections, Sections have groups, and groups have tasks. 我有一个项目类,继承继承了项目有节,节有组,组有任务。 Now I am displaying all of these in a table. 现在,我将所有这些显示在表中。 The table is created using this code. 该表是使用此代码创建的。

<table class="table table-condensed table-hover" border="1">
    <tr style="background-color: black; color: white">
        <th></th>
        <th>Manual/Group/Section</th>
        <th>Task</th>
        <th>Delete</th>
    </tr>
    @foreach (Manual manual in ViewBag.mlist)
    {
        <tr class="manualHeader no-hover jd-green">
            <th style="text-align:center"><input type="checkbox" /></th>
            <th>Manual Name @manual.name</th>
            <th></th>
            <th style="text-align:center"><button>Add Section</button></th>
        </tr>
        foreach (Section sections in @manual.sections)
        {
            <tr class="sectionHeader no-hover jd-yellow">
                <th style="text-align:center"><input type="checkbox" /></th>
                <th>Section Name : @sections.name</th>
                <th></th>
                <th style="text-align:center"><button>Add Group</button></th>
            </tr>
            foreach (Group group in @sections.groups)
            {
                <tr class="groupHeader no-hover jd-gray">
                    <th style="text-align:center"><input type="checkbox" /></th>
                    <th>Group Name : @group.name</th>
                    <th></th>
                    <th style="text-align:center"><button>Add Task</button></th>
                </tr>
                foreach (Task task in @group.tasks)
                {
                    <tr>
                        <th style="text-align:center"><input type="checkbox" /></th>
                        <th></th>
                        <th>Task Name:<input type="text" style="width:100%" value="@task.name" name="@task.name" /></th>
                        <th></th>
                    </tr>
                }
            }
        }
    }
</table>

The Script I am using to handle the toggling consists of this code 我用来处理切换的脚本包含以下代码

<script>
    $(document).ready(function () {
        $(".manualHeader").click(function () {
            $(this).nextUntil(".manualHeader").toggle();
        });
        $(".sectionHeader").click(function () { $(this).nextUntil(".manualHeader, .sectionHeader").toggle(); });
        $(".groupHeader").click(function () { $(this).nextUntil(".manualHeader, .sectionHeader, .groupHeader").toggle(); });
    });
</script>

Now I get why it isn't working properly, When you toggle lets say a group so all the tasks under it are hidden, then you toggle the manual which that group exists in and everything except the tasks that were hidden by clicking the group previously. 现在,我了解了为什么它无法正常工作,当您切换一个组时,使其隐藏了所有任务,然后您手动切换了该组所在的手册以及除已隐藏的任务以外的所有内容,方法是单击该组。 。 And I understand why this is happening due to the use of toggle() with untilNext() in my Script. 我知道为什么会这样,原因是在脚本中将toggle()与untilNext()一起使用。 My question is how do I fix it with some sort of conditional to check the visibility or something. 我的问题是如何使用某种条件检查它的可见性来修复它。

<script>
    $(document).ready(function () {
        $(".manualHeader").click(function () {
            var anyHidden = false;
            var allHidden = true;
            $(this).nextUntil(".manualHeader").each(function () {
                if ($(this).is(":visible"))
                    allHidden = false;
            });
            if (allHidden)
                $(this).nextUntil(".manualHeader").each(function () {
                    if ($(this).is(".sectionHeader"))
                        $(this).show();
                });
            else
                $(this).nextUntil(".manualHeader").hide();
        });
        $(".sectionHeader").click(function () {
            var anyHidden = false;
            var allHidden = true;
            $(this).nextUntil(".manualHeader, .sectionHeader").each(function () {
                if ($(this).is(":visible"))
                    allHidden = false;
            });
            if (allHidden)
                $(this).nextUntil(".manualHeader, .sectionHeader").each(function () {
                    if ($(this).is(".groupHeader"))
                        $(this).show();
                });
            else
                $(this).nextUntil(".manualHeader, .sectionHeader").hide();
        });
        $(".groupHeader").click(function () {
            var anyHidden = false;
            var allHidden = true;
            $(this).nextUntil(".manualHeader, .sectionHeader, .groupHeader").each(function () {
                if ($(this).is(":visible"))
                    allHidden = false;
            });
            if (allHidden)
                $(this).nextUntil(".manualHeader, .sectionHeader, .groupHeader").show();
            else
                $(this).nextUntil(".manualHeader, .sectionHeader, .groupHeader").hide();
        });
    });
</script>

This works to do what was wanted to be done 这可以做想要做的事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM