gpt4 book ai didi

asp.net-mvc - 在 Kendo TreeView 中获取所选节点的 id

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

我有这个 Controller 方法将树项发送到 View 中的树:

private IEnumerable<TreeViewItemModel> GetTrees()
{
InstallationPlaceModel ipm = new InstallationPlaceModel();
var gipo = ipm.getRootInstallationPlaces();
List<TreeViewItemModel> fullTree = new List<TreeViewItemModel>();

foreach (wsInstallationPlace.installationPlaceOutput father in gipo.installationPlaces)
{
var gipo2 = ipm.getChildInstallationPlaces(father.installationPlace.id);
List<TreeViewItemModel> childTree = new List<TreeViewItemModel>();

foreach (wsInstallationPlace.installationPlaceOutput child in gipo2.installationPlaces)
{
TreeViewItemModel childTreeItem = new TreeViewItemModel
{
Text = child.installationPlace.mediumDescription,
Id = child.installationPlace.id
};
childTree.Add(childTreeItem);
}
TreeViewItemModel fatherTreeItem = new TreeViewItemModel
{
Text = father.installationPlace.mediumDescription,
Id = father.installationPlace.id,
Items = childTree
};
fullTree.Add(fatherTreeItem);
}
ViewBag.mytree = fullTree;
return fullTree;
}

这是 Kendo Treeview :
@(Html.Kendo().TreeView()
.Name("treeview")
.DragAndDrop(true)
.Events(e => e.Select("onSelect"))
.BindTo((IEnumerable<TreeViewItemModel>)ViewBag.mytree)
)

这个函数来处理树节点的选择:
function onSelect(e) {
alert(this.text(e.node));
}

选择节点后,会显示带有节点文本的警报。我想显示节点的 id。我试过了:
function onSelect(e) {
alert(this.id(e.node));
}

但没有运气。正如您在 Controller 方法中看到的,我正在填充 textid 属性,但我只能访问文本。有什么帮助吗?

LIVE DEMO

最佳答案

要获取所选节点的 id ,您应该使用 $(e.node).data("id")

function onSelect(e) {
alert($(e.node).data("id"));
}

关于asp.net-mvc - 在 Kendo TreeView 中获取所选节点的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065997/

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