gpt4 book ai didi

jquery - 在页面加载时保持 Kendo Treeview 的扩展状态

转载 作者:行者123 更新时间:2023-12-03 22:51:41 27 4
gpt4 key购买 nike

我正在使用 Kendo Treeview 。导航到 Treeview 链接后,我需要保持 Treeview 展开状态。

@(Html.Kendo().TreeView()
.Name("treeview")
.HtmlAttributes(new {@class="demo-section",@style="height:700px;" })
.DataTextField("Name").DataUrlField("Name").DataUrlField("URL").ExpandAll(true)
.DataSource(dataSource => dataSource
.Read(read => read
.Action("GetUserMenue", "UserManagement")
)

)

)


public ActionResult GetUserMenue(int? id)
{
repUser = new UserManagementRepository();

List<UserMenue> model = repUser.getMenue(WebSecurity.GetUserId(User.Identity.Name));

if (!id.HasValue)
{
var emp = from e in model
select new
{
id = e.PermissionID,
Name = e.Name,
URL=e.URL,
hasChildren = e.hasChildren
};

return Json(emp, JsonRequestBehavior.AllowGet);
}
if (id.HasValue)
{
List<UserMenue> modelChild1 = repUser.getMenuLevel2(id);

var emp = from e in modelChild1
select new
{
id = e.PermissionID,
Name = e.Name,
URL = e.URL

};

return Json(emp, JsonRequestBehavior.AllowGet);
}


return Json(model, JsonRequestBehavior.AllowGet);
}

最佳答案

你来了 Doc

主要两个功能:

function saveExpanded() {
var treeview = $("#treeview").data("kendoTreeView");
var expandedItemsIds = {};
treeview.element.find(".k-item").each(function () {
var item = treeview.dataItem(this);
if (item.expanded) {
expandedItemsIds[item.id] = true;
}
});
Cookies.set('expanded', kendo.stringify(expandedItemsIds));
}

function setExpanded(data, expanded) {
for (var i = 0; i < data.length; i++) {
if (expanded[data[i].id]) {
data[i].expanded = true;
}
if (data[i].items && data[i].items.length) {
setExpanded(data[i].items, expanded);
}
}
}

只要确保你已经引用了这个 jquery plugin 来使用 $.cookie 函数

关于jquery - 在页面加载时保持 Kendo Treeview 的扩展状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29069792/

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