我有这个包含事件的表,单击它的图标(箭头)我创建新行(称为子事件),然后将其添加到当前行下。我想点击同一个图标来隐藏它的子事件,但只有他的。现在,如果我点击一个新事件(不同的行),它将切换每个隐藏的行,即使它们与当前行无关......
只是我试图强制获得某种UntilNext,但我无法使该功能正常工作,并且通过我正在执行的简单循环 atm 它跳过 oneEvent 但触发每个子行而不是我想要的那个。
$('.JSONArrow').on("click", function () {
var image = $(this);
var Row = image.closest("tr");
Row.toggleClass("Opened");
if (Row.hasClass("Opened")) {
image.attr("src", "/Images/downArrow.png")
if (!(Row.hasClass("alreadyOpen"))) {
var id = image.attr("id");
$.get("/Home/Child/" + id, function (data) {
Row.after(data);
Row.addClass("alreadyOpen");
});
}
} else {
image.attr("src", "/Images/rightArrow.png");
}
var tr = Row.nextAll('tr');
for (i = 0; i < tr.length; i++) {
var eventClass = $(tr[i]).attr('class');
if (eventClass == 'ChildEvent')
$(tr[i]).slideToggle()
else {
if (eventClass == 'oneEvent')
return;
}
}
});
必须很简单,才能使 nextUntil 仅在子行上工作,但到目前为止我还没有管理它,根据 jquery doc,它应该很简单,例如:
var tr = Row.nextUntil('tr',$(".oneEvent"));
for (i = 0; i < tr.length; i++) {
var eventClass = $(tr[i]).attr('class');
if (eventClass == 'ChildEvent'){
$(tr[i]).slideToggle()
}
}
但我不能让它工作。任何人都可以指出如何做到这一点,或者使用另一个我不知道的 jquery 函数将选择链接(childEvent)到我的 Row 变量而不是其他变量的所有('tr')。
如果您不了解 asp 或 mvc4,我不确定人们是否会更了解 hthml,但这里是:编辑::
<div class="TableHolder">
<table id="mainTable">
<thead>
<tr class="header">
<th class="iconColumn">Child</th>
<th>Date </th>
.... other <th>
</th>
</tr>
</thead>
@Html.EditorFor(x => x.logs)
</table>
这就是每个说的表格行:
string dynamicClass = "";
if (Model.Parent == null )
{
dynamicClass = "oneEvent";
}
else
{
dynamicClass = "ChildEvent";
}
}
<tr class="@dynamicClass">
<td class="iconColumn">
@if (Model.Parent == null )
{
<img class="JSONArrow" id="@Model.EventID" src="~/Images/rightArrow.png"/>
}
</td>
<td>@Model.TimeUTC.ToString("dddd, dd MMMM yyyy")<br />@Model.TimeUTC.ToString("HH:mm:ss") </td>
.... other column
</tr>
我会尽量简化我所说的:
您有行。(事件)当您单击行(事件)时,新的动态行会出现在其下方(称为 ChildEvent)。
如果您在行(事件)上再次单击,如果行存在于他之下,则隐藏行,但前提是它们是 ChildEvent 类。
我当前的代码隐藏了桌子上的所有 ChildEvent,我只想隐藏(事件)点击下的那些。
如果用户单击行(事件),它将显示(ChildEvent)(如果存在),但仅显示与单击的行(事件)相关的(childEvent),而不是整个表的ChildEvent。
childEvent 只能添加到其相关 Event 下。
重新编辑:
row.nextUntil(".oneEvent", ".ChildEvent").slidetoggle();
这就是我想要的,文本:切换我点击的下方的 tr,如果他们有 ChildEvent 类。测试直到你到达一个拥有“oneEvent”类的tr。
我只是无法理解参数去了哪里。
重新编辑:
<table>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
</table>
点击:
<table>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
</table>
点击同一个事件
<table>
<tr class="oneEvent, alreadyOpened"></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
</table>
点击一个新的事件:
<table>
<tr class="oneEvent, alreadyOpened"></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
</table>
点击另一个新的事件
<table>
<tr class="oneEvent, alreadyOpened"></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=oneEvent></tr>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
点击前一个事件:
<table>
<tr class="oneEvent, alreadyOpened"></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=oneEvent></tr>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class="oneEvent, alreadyOpened"></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>
单击第一个 OneEvent :
<table>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class=oneEvent></tr>
<tr class="oneEvent, Opened, alreadyOpened"></tr>
<tr class=ChildEvent display = true></tr>
<tr class=ChildEvent display = true></tr>
<tr class="oneEvent, alreadyOpened"></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=ChildEvent display = false></tr>
<tr class=oneEvent></tr>
<tr class=oneEvent></tr>