Javascript 使用editoptions用JSON数据填充jqgrid下拉列表

Javascript 使用editoptions用JSON数据填充jqgrid下拉列表,javascript,jquery,asp.net,json,jqgrid,Javascript,Jquery,Asp.net,Json,Jqgrid,我对web开发是新手,我遇到过这个问题,并且研究和尝试了许多其他方法,但都没有成功。我只需要用数据库中的值填充jqgrid中的下拉列表。我用于执行此操作的url以JSON的形式给出正确的响应,如下所示(请注意,我仅通过选定字段发送): 当我尝试从下面的方法中执行dropdownlist而不从url读取json时,它可以100%工作,但是它不是动态的,我使用方法getAllSelectOptions(),在网格中使用它的地方如下所示: function getAllSelectOptions()

我对web开发是新手,我遇到过这个问题,并且研究和尝试了许多其他方法,但都没有成功。我只需要用数据库中的值填充jqgrid中的下拉列表。我用于执行此操作的url以JSON的形式给出正确的响应,如下所示(请注意,我仅通过选定字段发送):

当我尝试从下面的方法中执行dropdownlist而不从url读取json时,它可以100%工作,但是它不是动态的,我使用方法getAllSelectOptions(),在网格中使用它的地方如下所示:

function getAllSelectOptions() {

var services = {
'1':'Forex', '2':'Tellers', '3':'Consultants'};

return services;

}
我的网格代码:

url: "http://localhost:8080/service.svc/employees/3"
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
height: '250',                           
colNames: ['ID', 'Name', 'Surname', 'Username', 'Email', 'Branch ID', 'User Type', 'Status', 'Speciality'],
                            colModel: [
                                    { name: 'employee_id', index: 'employee_id'},
                                    { name: 'employee_name', index: 'employee_name', editable: true },
                                    { name: 'employee_surname', index: 'employee_surname', editable: true },
                                    { name: 'employee_username', index: 'employee_username', editable: true },
                                    { name: 'employee_email', index: 'employee_email', editable: true },
                                    { name: 'branch_id', index: 'branch_id', editable: true },
                                    { name: 'user_type', index: 'user_type', editable: true },
                                    { name: 'employee_state', index: 'employee_state', editable: true },
                                    { name: 'employee_speciality', index: 'employee_speciality', editable: true,
                                        sortable: true,
                                        align: 'center',
                                        editable: true,
                                        cellEdit: true,
                                        edittype: 'select',
                                        formatter: 'select',
                                        editoptions: { value: getAllSelectOptions() }

                                    }],

                                rowNum: 20,
                                rowList: [10, 20, 30],
                                pager: '#pager_jqgrid',
这是完美的。 但是,我使用下面的方法来替换getAllSelectOptions()方法,当我使用警报框时,它会返回信息,但不起作用

function availAtBranch() {


                            $.ajax({
                                type: "GET",
                                url: "http://localhost:8080/service.svc/branch/3",
                                dataType: "json",
                                success: function (data) {
                                    $.each(data.serviceBranchResult, function (i, obj) {
                                        //alert(obj.service_id + ":" + obj.service_name);
                                        var div_data = obj.service_name + ":" + obj.service_name;
                                        //alert(div_data);

                                    });

                                    return div_data;

                                }

                            });
我认为这与如何将JSON解析为editoptions方法或通过发送对象有关。如何使JSON采用getAllSelectOptions()方法中描述的格式,或者如何在dropdownlist中显示数据。先谢谢你

function availAtBranch() {


                            $.ajax({
                                type: "GET",
                                url: "http://localhost:8080/service.svc/branch/3",
                                dataType: "json",
                                success: function (data) {
                                    $.each(data.serviceBranchResult, function (i, obj) {
                                        //alert(obj.service_id + ":" + obj.service_name);
                                        var div_data = obj.service_name + ":" + obj.service_name;
                                        //alert(div_data);

                                    });

                                    return div_data;

                                }

                            });