Loading of Kendo UI panelbar using datasource

六眼飞鱼酱① 提交于 2019-12-23 05:43:08

问题


I am trying to load panelbar dynamically using datasource. Actually In the documentation I got information with using ajax only, so I have implemented like this,

    $.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"}]
                    });
                }
});

but with this I am not able to display all values, I think this is not the correct way of loading panel bar to display all values,How to display all values in panelbar


回答1:


You should be iterating over your result array. You can use jQuery Map function E.g.:

$.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 
                });
            }
});


来源:https://stackoverflow.com/questions/13718665/loading-of-kendo-ui-panelbar-using-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!