gpt4 book ai didi

kendo-ui - 为我的 json 数据配置 kendo ui treeview

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

我有以下数据:

[
{"id":1,"parendId":0,"name":"Foods","hasItems":"true},
{"id":2,"parentId":1,"name":"Fruits","hasItems":"true"},
{"id":3,"parentId":1,"name":"Vegetables","hasItems":"true"},
{"id":4,"parentId":2,"name":"apple","hasItems":"false"},
{"id":5,"parentId":2,"name":"orange","hasItems":"true"},
{"id":6,"parentId":3,"name":"tomato","hasItems":"true"},
{"id":7,"parentId":3,"name":"carrot","hasItems":"true"},
{"id":8,"parentId":3,"name":"cabbage","hasItems":"true"},
{"id":9,"parentId":3,"name":"potato","hasItems":"true"},
{"id":10,"parentId":3,"name":"lettuce","hasItems":"false"}
]

有人可以告诉我如何为上述数据配置 kendo ui treeview 吗?
另外,是否可以在 kendo ui 下拉列表中使用此 Treeview ?

更新:

这是我到目前为止...
categories = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: UrlThatFetchesData
}
},
schema: {
model: {
id: 'id',
parentId: 'parentId',
name: 'name'
}
}
});

$('#tvCategories').kendoTreeView({
dataSource: categories,
dataTextField: 'name',
dataValueField: 'id'
});

所有项目都显示为主要类别,一个在另一个的正下方。
如何让 Treeview 使用 parentId?

最佳答案

您是否尝试将其他数据嵌入到 Treeview 项中?如果是这样,您的 KendoTreeview 应如下所示:

@(  Html.Kendo().TreeView()
.Name("Treeview")
.DataTextField("name") //display text
.DataSource(dataSource => dataSource
.Read(read => read
.Action("ActionThatFetchesData", "ControllerName")
)
)
.TemplateId("treeview-template") //name of the template
)

然后使用将显示 json 的 Kendo 模板
<script id="treeview-template" type="text/kendo-ui-template">
<span>#: item.id#</span>
<span>#: item.parentId#</span>
<span>#: item.name#</span>
<span>#: item.hasItems#</span>
</script>

关于kendo-ui - 为我的 json 数据配置 kendo ui treeview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14845328/

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