select2中没有绑定数据数组

时间:2017-05-30 07:41:26

标签: javascript jquery

这个数据数据没有绑定,可以任意设置

presentProfile = Object {authenticateCode: null,frontendPermission:
    Array(3)
    0:"administrator"
    1:"author"
    2:"contributor" }   

    jQuery.each(presentProfile.frontendPermission, function (index, data) {
           jQuery("#bis_frontend_display_roles").select2("val", data);
        });

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

var presentProfile = {
    authenticateCode: null,
    frontendPermission:[{id:0, text:"administrator"},{id:1, text:"author"},{id:2, text:"contributor"}] 
} ;

jQuery("#bis_frontend_display_roles").select2({data: presentProfile.frontendPermission});