EasyUI入門7 datagrid根據列值設定checkbox的繫結狀態

 datagrid根據列值(True,False)設定checkbox的繫結狀態.

https://www.itread01.com/content/1549477294.html

//彈出角色設定視窗

function AuthoritySetting() {


    //繫結新值

    var row = $('#dg').datagrid('getSelected');

    if (row) {

        $('#dlgAuthoritySetting').dialog('open');

        $('#tbxRoleCode').textbox('setValue', row.角色程式碼);

        $('#tbxRoleName').textbox('setValue', row.角色名稱);


        $.ajax({

            contentType: "application/x-www-form-urlencoded; charset=UTF-8",

            url: "../../Controller/Interface/ComAuthority.ashx?Action=BindRole",

            type: "get",

            data: {

                "roleCode": encodeURIComponent($('#tbxRoleCode').textbox('getText')),

            },

            dataType: "json",

            success: function (data) {

                $("#dgrole").datagrid("options").pageNumber = 1;

                $("#dgrole").datagrid("loadData", data);


                if (data) {

                    $.each(data.rows, function (index, item) { 

                        if (item.checked == "True") {

                            $('#dgrole').datagrid('checkRow', index);

                        }

                        else {

                            $('#dgrole').datagrid('uncheckRow', index);

                        }

                    });

                }

            }


        });


    }



}

核心部分

if (data) {
    $.each(data.rows, function (index, item) { 
        if (item.checked == "True") {
            $('#dgrole').datagrid('checkRow', index);
        }
        else {
            $('#dgrole').datagrid('uncheckRow', index);
        }
    });
}

留言

這個網誌中的熱門文章

考績被打差了 輕率離職會更傷

Arrays - DS (Reverse array) [Easy]

WireMock