2017-01-03 11 views
1

2つのドロップダウン選択ボックスがあります。私はAngularJSを使用してドロップダウンにオプションを表示しています。select2()を使用してドロップダウンで選択したオプションを表示

私のスクリプトでは、$(".select2_demo_1").select2();を使用すると、一度に1つのドロップダウンが選択されたオプションを表示します。選択肢を表示するために両方のドロップダウンを表示したい。親切に助けが必要です。

<select id="one" class="select2_demo_1 form-control" ng-model="orgs" ng-options="item.OrganizationTypeTitle for item in organization"></select> 
<select id="two" class="select2_demo_1 form-control" ng-model="industry" ng-options="i.IndustryTypeTitle for i in industries"></select> 

var getOrganizationTypes = OrgService.getOrganizationTypes(); 

getOrganizationTypes.then(function (response) { 
    $scope.organization = response.data; 
    $scope.orgs = $scope.organization[0]; 

}, function() { 
    alert('can not get Organization Types!'); 
}); 

var getIndustryTypes = OrgService.getIndustryTypes(); 

getIndustryTypes.then(function (response) { 

    $scope.industries = response.data; 
    $scope.industry = $scope.industries[0]; 

}, function() { 

    alert('can not get industry types'); 

}) 

答えて

0

あなたが同じCSSから値を取得するためのループを必要とする

 $(function() { 
     var v = []; 
     $(".select2_demo_1").each(function(){ 
      v.push($(this).val()); 
     }) 
     }); 

サンプル:Demo On jsfiddle

<link href="http://ivaynberg.github.com/select2/select2-3.2/select2.css" rel="stylesheet"/> 
<script src="http://ivaynberg.github.com/select2/select2-3.2/select2.js"></script>  


     <select class="select2_demo_1" name="drp_Books_Ill_Illustrations" > 
      <option value="1" selected>1</option> 
      <option value="2">2</option> 
      <option value="3">3</option> 
      <option value="4">4</option> 
     </select> 



     <select class="select2_demo_1" name="drp_Books_Ill_Illustrations" > 
      <option value="1">1</option> 
      <option value="2" selected>2</option> 
      <option value="3">3</option> 
      <option value="4">4</option> 
     </select> 


<button class="getValue">Get Value</button> 
<button class="setValue"> Set value </button> 



$(".getValue").click(function() { 
      var v = []; 
     $(".select2_demo_1").each(function(){  
      v.push($(this).val()); 
      alert($(this).val()) 
     }) 
    }); 
関連する問題