下拉列表未保存保存数据的值

时间:2016-07-21 19:49:51

标签: javascript html css angularjs

W DrodownList

当我从下拉列表中选择一个值时,请说"练习列​​表"然后点击保存按钮,再次修改该项目我可以看到下拉列表没有保持其选定的值,即"练习列​​表"。相反,它保持其默认值,即"我的列表"。如何在保存数据后保持所选值?

这是我的HTML代码:

 <select id="{{::prefix}}_Select_Practice" name="FreeTextDrugSchedule" ng-options="option as option.name for option in data.practiceOptions" class="form-control medium" ng-model="data.saveIn" style="margin-bottom: 5px;">
                <option value="" selected="selected">My list</option>
            </select>
<button id="{{::prefix}}_Button_Submit" class="btn btn-primary" ng-click="validations = null; doSubmit()">{{submitVerb}}</button>

这是我的js文件代码:

 $scope.doSubmit = function (dataToSubmit) {
                        $scope.submitted = true;
                        if (dataToSubmit) {

                            if ($scope.data.saveIn) {
                                dataToSubmit.dataToSubmit.saveIn = $scope.data.saveIn;
                            }
                            $scope.data = dataToSubmit.dataToSubmit ? dataToSubmit.dataToSubmit : dataToSubmit;
                        }

                        validateSubmission();

                        // TODO simplify this validation
                        if ($scope.EnterDetailsForm.$invalid || $scope.showEffectiveDateError ||
                            $scope.showEffectiveDateRangeError || ($scope.sigValidations &&
                            $scope.sigValidations.length)
                            || ($scope.data.pharmacy1 && $scope.data.pharmacy1 == $scope.data.pharmacy2)
                            || ($scope.showMDD && (!$scope.data.medication.maximumDailyDose || ($scope.showMDD == 'pd' && !$scope.data.medication.maximumDailyDoseUnit)))
                            || $scope.showProviderError
                            || $scope.showSupervisorError
                            || $scope.drugMinError
                            || $scope.showPrimaryError) {

                            $scope.validations.push({
                                name: 'Invalid Entry',
                                msg: 'Please correct all errors on this form to continue.'
                            });

                            if ($scope.entity == 'Prescription') {
                                $scope.scrollToError = true;
                            }
                        } else if ($scope.entity == 'Prescription' && !validateDuration()) {
                            $scope.$emit('ghostMessage', 'The length of the prescription should not be more than 365 days');
                        } else { //proceed with submission
                            // prepare the data to be submitted to the alert checker
                            var dataToSubmit = prepareDataToSubmit();

                            // validate payload before submit
                            if (dataToSubmit.medication.lastRefillDate && dataToSubmit.medication.startDate && dataToSubmit.medication.lastRefillDate.date < dataToSubmit.medication.startDate.date) {
                                $scope.$emit('ghostMessage', 'Last written date cannot be before start date.');
                            } else if (dataToSubmit.medication.lastRefillDate && dataToSubmit.medication.stopDate && dataToSubmit.medication.lastRefillDate.date > dataToSubmit.medication.stopDate.date) {
                                $scope.$emit('ghostMessage', 'Last written date cannot be after stop date.');
                            } else if (dataToSubmit.medication.diagnoses && dataToSubmit.medication.diagnoses.length == 2 && dataToSubmit.medication.diagnoses[0].code &&
                                dataToSubmit.medication.diagnoses[0].code == dataToSubmit.medication.diagnoses[1].code) {
                                $scope.$emit('ghostMessage', 'You may not specify the same diagnosis code for both primary and secondary diagnoses');
                            } else if ($scope.entity != 'FavoriteRx' && $scope.showDAWGenericWarning && !$scope.formularyCheckedForDAWWarning) {
                                checkFormularyAlertsForDAWWarning(dataToSubmit);
                            } else {
                                $scope.formularyCheckedForDAWWarning = false;

                                // check dose alerts if necessary
                                dataToSubmit.schedules = angular.copy(schedules);
                                if ($scope.entity == 'Prescription' && doseCheckNeeded) {
                                    checkDoseAlerts(dataToSubmit);
                                } else { // done; process submission
                                    $scope.submit({data: dataToSubmit, optionCodes: $scope.optionCodes});
                                    $scope.loading = 0;
                                }
                            }
                        }
                    };

1 个答案:

答案 0 :(得分:1)

我不确定你要求的是什么,或者你“保存”数据是什么意思,但我会尝试提供一些帮助。

我不知道angular.js,但我的建议是将select包装在一个表单中(我假设你正在做),然后使用angluar.js中的post值设置值(如果可以的话)去做)。这样,如果您重新加载页面,它将不会加载默认值。此外,如果您只是在选择新选项后仅在浏览器中检查元素,则不会显示已选择新选项(即所选=“”属性仍将是默认选项)。