Editoptions显示但不接受下拉列表中选择的值

时间:2016-08-07 12:38:45

标签: c# jquery ajax jqgrid

我有一个jqgrid下拉列表,用我的数据库中的Json数据填充。它显示完美,但是当单击一个选项时,它不会接受所选的值并将其发送出去。换句话说,它只是在下拉列表中显示而已。这是我正在使用的colmodel字段的代码:

 {
          name: 'employee_speciality', index: 'employee_speciality', editable: true,
          editrules: { required: true },
          sortable: true,
          align: 'center',
          editable: true,
          cellEdit: true,
          edittype: 'select',
          formatter:'select',
          editoptions: { 
                  dataUrl:"http://localhost:8080/service.svc/serviceBranch",
                  buildSelect: function (response) {
                  var data = typeof response === "string" ?
                  $.parseJSON(response) : response,
                  s = "<select>";
                  s += '<option selected="selected" style="display:none;">Choose here</option>';
                       $.each(data.serviceBranchResult, function () {
                             s += '<option value="' + this.service_name + '">' + this.service_name + 
                             '</option>';
                  })

         return s + "</select>";
    }
  }
}],

这是我检索数据的地方,其中employee_speciality是唯一一个包含下拉列表的数据:

function saveData() {

                            var rowid = $("#jqgrid").jqGrid('getGridParam', 'selrow');
                            var rowData = $("#jqgrid").getRowData(rowid);

                            var employee_name = rowData.employee_name;
                            var employee_surname = rowData.employee_surname;
                            var employee_username = rowData.employee_username;
                            var employee_email = rowData.employee_email;
                            var branch_id = rowData.branch_id;
                            var user_type = rowData.user_type;
                            var employee_state = rowData.employee_state;
                            var employee_speciality = rowData.employee_speciality;


                            alert(employee_speciality); //to check

                                var gridData = {
                                    employee_name: employee_name,
                                    employee_surname: employee_surname,
                                    employee_username: employee_username,
                                    employee_email: employee_email,
                                    branch_id: branch_id,
                                    user_type: user_type,
                                    employee_state: employee_state,
                                    employee_speciality: employee_speciality

                                };

                                gridData = JSON.stringify(gridData);





                                $.ajax({
                                    type: "POST",
                                    url: "Employees.aspx/save",
                                    data: gridData,
                                    contentType: "application/json; charset=utf-8",
                                    dataType: 'json',
                                    success: function (response, textStatus, xhr) {
                                        alert(employee_speciality);
                                        location.reload(true);
                                    },
                                    error: function (xhr, textStatus, errorThrown) {
                                        alert(employee_speciality);
                                        Abort();
                                        alert("Please enter all fields");

                                    }
                                })

请问我能否了解为何会发生这种情况,我们非常感谢您的帮助。提前致谢

1 个答案:

答案 0 :(得分:0)

我找到了解决问题的方法。取出格式化程序:&#39;选择&#39;为我工作。感谢您的时间@David