我正在尝试使用数据源动态加载panelbar。 实际上在文档中我只获得了使用ajax的信息, 所以我已经实现了这样,
$.ajax({
type: "POST",
url: '/Home/GetPanelInfo',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (json) {
$("#panelBar").kendoPanelBar({
expandMode: "single",
id: "usr_id",
dataSource: [{ text: json[0].groups_name, expand: true, contentUrl: "/Home/Index" },
{ text: json[1].groups_name, expand: true, contentUrl: "/Home/Index" },
{ text: json[3].groups_name, expand: true, contentUrl: "/Home/Index"}]
});
}
});
但有了这个,我无法显示所有值, 我认为这不是加载面板栏以显示所有值的正确方法,如何在面板栏中显示所有值
答案 0 :(得分:0)
您应该遍历结果数组。您可以使用jQuery Map function例如:
$.ajax({
type: "POST",
url: '/Home/GetPanelInfo',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (json) {
var dataSource = $.map(json, function(obj){
return {
text: obj.groups_name,
expand: true,
contentUrl: "/Home/Index"
};
});
$("#panelBar").kendoPanelBar({
expandMode: "single",
id: "usr_id",
dataSource: dataSource
});
}
});