2017-10-10 19 views
0

私はjsonスキルを持っていますが、model.skillsからスキルをマルチセレクトする必要があります。multipleSkills()を使用して選択した値をarrayvalues[]にプッシュしますが、重複値をarrayvaluesにプッシュしないでください。配列内に重複オブジェクトがありません

JSON:

var skills = 
[{"name":{"skillId":1,"skillName":"JAVA"}}, 
{"name":{"skillId":2,"skillName":"C"}}, 
{"name":{"skillId":3,"skillName":"DEVOPS"}}, 
{"name":{"skillId":4,"skillName":"ANGULAR JS"}}, 
{"name":{"skillId":41,"skillName":"drupal"}}, 
{"name":{"skillId":42,"skillName":"backbone js"}}, 
{"name":{"skillId":43,"skillName":"nodejs"}}, 
{"name":{"skillId":44,"skillName":"phone gap"}}, 
{"name":{"skillId":45,"skillName":"scala"}}, 
{"name":{"skillId":46,"skillName":"spark"}}] 

HTML:

<input class="form-control1" type="text" name="skills" placeholder="Core Skills" 
     ng-model="model.Skills" ng-focus="skillsforJobs(model.Skills)" 
     typeahead ="skill as skill.name.skillName for skill in skills | filter:$viewValue | limitTo:10" 
     typeahead-on-select="multipleSkills(model.Skills)" 
     ng-minlength =1 /> 

JS:

$scope.arrayvalues = []; 
    $scope.multipleSkills = function(data){ 
     if($scope.arrayvalues.length <1){ 
       $scope.arrayvalues.push(data); 
      } else if($scope.arrayvalues.length > 0){ 
      if($scope.arrayvalues.indexOf($scope.model.Skills) == -1) {     
       if($scope.model.Skills != ""){ 
        for(var i=0; i<$scope.arrayvalues.length;i++){ 

       $scope.arrayvalues[i].name.skillId.indexOf(data.name.skillId){ 
       $scope.arrayvalues.push(data); 
            $scope.model.Skills = ""; 

        } 

        } 

     } 

     } 

答えて

0

このgithubのプロジェクトを参照してください。 AngularJS Dropdown Multiselect

HTML

<script type="text/javascript" src="angularjs-dropdown-multiselect.js"></script>    
    <div ng-app="myApp" ng-controller="myCtrl"> 
      <div ng-dropdown-multiselect="" options="example1data" selected-model="example1model"></div>  
      </div> 

JS

var app = angular.module('myApp', ['angularjs-dropdown-multiselect']); 
app.controller('myCtrl', function($scope) { 

}); 
関連する問題