gpt4 book ai didi

javascript - 在mvc中刷新后使行可点击

转载 作者:行者123 更新时间:2023-12-03 09:37:34 25 4
gpt4 key购买 nike

我想在刷新后使一行可点击。我的观点是这样的:

@foreach (var item in Model) {
<tr class="@(item.Id == (int)(Session["Id"] ?? 0) ? ".tr.sfs-selected .table.sfs-selectable tbody .dataTable sfs-selected .dataTable sfs-selectable .table-responsive" : String.Empty)" onclick="'<tr>'" data-url="@Url.Action("Index", new RouteValueDictionary { { "id", item.Id } })">
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsEnabled)
</td>
<td>
</tr>
}

我有这个 jQuery:

$("table.sfs-selectable tbody").on("click", "tr", function (ev) {
var $row = $("tr.sfs-selected").each(function(){
selectRow($row, !$row.hasClass("sfs-selected"));
});
});

但是刷新后未单击该行。

谢谢

View :

   <table class="table table-striped table-bordered table-hover dataTable sfs-selectable sfs-col1-right-aligned">

<thead>
<tr>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.Id).ToString(), "Sort-Product", new { sortColumn = "id", sortOrder = (ViewBag.sortColumn == "id" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("id", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.Name).ToString(), "Sort-Product", new { sortColumn = "name", sortOrder = (ViewBag.sortColumn == "name" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("name", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.IsEnabled).ToString(), "Sort-Product", new { sortColumn = "enabled", sortOrder = (ViewBag.sortColumn == "enabled" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("enabled", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.FormName).ToString(), "Sort-Product", new { sortColumn = "formname", sortOrder = (ViewBag.sortColumn == "formname" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("formname", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.TemplateName).ToString(), "Sort-Product", new { sortColumn = "design", sortOrder = (ViewBag.sortColumn == "design" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("design", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.RouteLink(Resources.Entity.Product.PublicUrl, "Sort-Product", new { sortColumn = "urlname", sortOrder = (ViewBag.sortColumn == "urlname" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString, filter = ViewBag.Filter })
@ViewHelper.GetSortIndicator("urlname", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th>
@Html.DisplayNameFor(model => firstItem.SubmittedForms)
</th>
<th>
@Html.RouteLink(Html.DisplayNameFor(model => firstItem.ModificationDate).ToString(), "Sort-Product", new { sortColumn = "modified", sortOrder = (ViewBag.sortColumn == "modified" && ViewBag.sortOrder != "desc") ? "desc" : "", searchString = ViewBag.SearchString })
@ViewHelper.GetSortIndicator("modified", ViewBag.sortColumn, ViewBag.sortOrder)
</th>
<th class="hidden"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {

<tr class="@(item.Id == (int)(Session["Id"] ?? 0) ? ".tr.sfs-selected .table.sfs-selectable tbody .dataTable sfs-selected .dataTable sfs-selectable .table-responsive" : String.Empty)" data-url="@Url.Action("Index", new RouteValueDictionary { { "id", item.Id } })">
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsEnabled)
</td>
<td>
@{
bool viewLink = item.IsEnabled;
if (!String.IsNullOrEmpty(item.FormName)) {
var form = item.FormLibraryEntry;
if (form == null) {
viewLink = false;
@Html.DisplayFor(modelItem => item.FormName)
<em>(@Resources.Entity.Environment.Removed)</em>
}
else {
@Html.DisplayFor(modelItem => form.Name)
<a href="@Url.Action("Details", "FormLibrary", new { id = item.FormName })"><i class="fa fa-fw fa-external-link-square text-info"></i></a>
}
}
}
</td>
<td>
@{
if (!String.IsNullOrEmpty(item.TemplateName)) {
var template = item.TemplateLibraryEntry;
if (template == null) {
viewLink = false;
@Html.DisplayFor(modelItem => item.TemplateName)
<em>(@Resources.Entity.Environment.Removed)</em>
}
else {
@Html.DisplayFor(modelItem => template.Name)
<a href="@Url.Action("Details", "DesignTemplate", new { id = item.TemplateName })"><i class="fa fa-fw fa-external-link-square text-info"></i></a>
}
}
}
</td>
<td>
@if (!String.IsNullOrEmpty(item.UrlName)) {
var defaultProductUri = CustomerConfig.ToHostUri(Request.Url.Scheme, defaultHostHeader, Request.Url.Port, (isProduction ? "" : "TEST/") + item.UrlName);
if (viewLink) {
@item.UrlName
<a href="@defaultProductUri.ToString()" title="@Resources.Entity.Product.ViewProduct" target="_blank"><i class="fa fa-fw fa-external-link-square text-info"></i></a>
}
else {
@item.UrlName
}
}
</td>
<td>
@{

int cnt = item.SubmittedForms.Where(prod => prod.Order.IsProduction == isProduction).Count();
@(cnt.ToString() + " ")
if (cnt > 0) {
<a href="@Url.Action("Index", "SubmittedForms", new { filter = item.Id })">
<i class="fa fa-fw fa-external-link-square text-info"></i>
</a>

}
}
</td>
<td class="text-nowrap">
@item.ModificationDate.ToString("G")
</td>
<td class="hidden">
<span>


@if (!String.IsNullOrEmpty(item.UrlName) && !String.IsNullOrEmpty(item.FormName)) {
@Html.RouteLink(Resources.Action.Navigation.Preview, "ProductPreview", new { productUrl = item.UrlName, customerSchema = custSchema }, new { target = "_blank" })
}
else { @(Resources.Action.Navigation.Preview) }
| @Html.ActionLink(Resources.Action.Navigation.Details, "Details", new { id = item.Id })
| @Html.ActionLink(Resources.Action.Navigation.Edit, "Edit", new { id = item.Id })
</span>
</td>



</tr>



}





</tbody>
</table>

所以我里面有tbody。但问题是现在我必须双击一行

这是 selectRow 函数:

function selectRow($row, doSel) {
var $section = $row.closest("section");
if (doSel) {
$section.find("tr.sfs-selected").removeClass("sfs-selected");
$row.addClass("sfs-selected");
$section.find(".sfs-actionbutton").each(function (index) {
var $btn = $(this);
$btn.addClass("disabled");
var href = $row.find("td:last a").filter(function () {
return $(this).text().trim() == $btn.text().trim();
}).attr("href");

if (href) {
$btn.attr("href", href).removeClass("disabled");
if ($btn.parent().is(".btn-group")) {
$btn.parent().children("a").removeClass("disabled");
$btn.attr("data-href", href + "/");
$btn.attr("href", href + "/" + $(".sfs-select-preview-template .active a").attr("href"));
}
}
});
}
else {
$row.removeClass("sfs-selected");
$section.find(".sfs-actionbutton").addClass("disabled");
}
}

最佳答案

你只是有错误的选择器,我猜它应该是这样的:

var $row = $("tr.sfs-selected").each(function(){
selectRow( $(this), $(this).hasClass("sfs-selected"));
});

重点是在 each() 方法中,您可以使用 this 关键字获取集合元素之一。

关于javascript - 在mvc中刷新后使行可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31285480/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com