会话值不会保留在选择框中

时间:2018-03-30 17:47:49

标签: angularjs angularjs-ng-model angularjs-ng-options angularjs-ng-value

Here is Picture For my issue

我已动态填充选择框数据,在设置会话后,即使页面重新加载,也必须选择这些值

填充选择框选项的代码使用ajax get方法

 else if (value.sourceType > 0) {
        $('#SOURCE_TYPE').append('<option data-ng-value="' + 
        value.sourceName +'">'+ value.sourceName + '</option>');
 }

1.所选会话值应放在选择框

脚本

var app = angular.module("app", ['ngMessages']);
app.controller("quotationController",
  function($scope,$window) {

     $scope.quotation =[];
    $scope.contactId = null;
    $scope.quotation.drpContactType=$window.sessionStorage.getItem( 'drpContactType' );
    $scope.quotation.sourceType = $window.sessionStorage.getItem('sourceType');

    $scope.submit = function(){
      $window.sessionStorage.setItem('drpContactType',$scope.quotation.drpContactType);
      $window.sessionStorage.setItem('sourceType', $scope.quotation.sourceType);

    };

    fnendtmotoronload();
  });
 function fnendtmotoronload() {
var status = true;
var contactId = document.getElementById("CONTACT_TYPE").value;
var CONTEXT_PATH = '<%=request.getContextPath()%>/';

$.ajax({
  type : "GET",
  url : CONTEXT_PATH + "quotationDrop",
  data : contactId,
  contentType : 'application/json; charset=utf-8',
  dataType : 'json',
  success : function(result) {
    $.each(result, function(index, value) {
      if (value.contactType > 0) {
        $('#CONTACT_TYPE').append(
            '<option data-ng-value="' + value.contactName + '">'
                       + value.contactName + '</option>');
      } else if (value.sourceType > 0) {
        $('#SOURCE_TYPE').append(
            '<option data-ng-value="' + value.sourceName + '">'
                + value.sourceName + '</option>');
      } 
    });

  }
});
return status; 
}

HTML

<div class="col-sm-8">
<select ng-model="quotation.sourceType" ng-option="{{quotation.sourceType}}" required id="SOURCE_TYPE"
  class="form-control">
  <!-- <option selected="selected" value="0">--SELECT--</option> -->
</select>

来自数据库的数据

{
  "contactType": 0,
  "contactActiveStatus": "\u0000",
  "createdBy": 0,
  "sourceType": 2,
  "accountCode": 0,
  "sourceName": "ADMIN",
  "newIcNo": 0,
  "businessRegNo": 0,
  "oldIcNo": 0,
  "quotationID": 0,
  "nameddriversno": 0,
  "namedage": 0,
  "extracoverageid": 0,
  "mpaid": 0

},

0 个答案:

没有答案