2017-07-26 8 views
0

私はマルチセレクションのeasyuiコンボボックスを持っています。制限を超えて選択しようとすると、ユーザーに警告し、アイテムを選択できないように、選択可能なアイテムの数に制限を設けています。これは私のコードです。 onSelect方法でeasyuiコンボボックスの選択数を制限する

$("#assessment_content_items_select_standards").combobox({ 
     data: $rootScope.assessmentItemsFilters.selectedStandards, 
     valueField: 'value', 
     textField: 'label', 
     multiple: true,   
     onSelect: function (standard) 
     { 
      var selectedStandardsCount = 0; 
      angular.forEach($rootScope.assessmentItemsFilters.selectedStandards, function (stan) { 
       if (stan.selected == true) { 
        selectedStandardsCount++; 
       } 
      }); 

      if (selectedStandardsCount >= 25) { 
       alert("You have reached the maximum selected standards allowed of 25"); 
      } 
      else { 
       standard.selected = true; 
      } 
     }, 
     onUnselect: function (standard) { 
      standard.selected = false; 
     }      
    }); 

私は選択されたカウントを取得し、それはそれだけで警告を行い、それがその選択をtrueに選択設定しない25ことがよりだ場合。

私が抱えている問題は、データが選択されたものとして表示されても、項目が選択されたものとして表示されることです。私は選択を解除するために以下を試しましたが、違いは見られません。

standard.selected = false 
$("#assessment_content_items_select_standards").combobox('unselect', standard); 

私の質問はどのようにしてオプションが選択されなくなるのですか、またはドロップダウンに制限を設けるより良い方法がありますか?

答えて

0

は、この方法を試してください。

$('#assessment_content_items_select_standards').combobox({ 
    onSelect: function (standard) { 
     var count = $("div.combobox-item-selected").length; 
     if (count > 25) { 
      alert("You can only choose 25."); 
      $('#assessment_content_items_select_standards').combobox('unselect', standard. value); 
     } 
    } 
}); 

Reference Documentation

関連する問題