I have a json skills , I need to multiselect the skills from dropdown model.skills
, I use multipleSkills()
to push the selected values in arrayvalues[]
, but I should not push duplicate values into 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 = "";
}
}
}
}
Source: AngularJS
from Angular Questions https://angularquestions.com/2017/10/10/not-pushing-duplicate-object-in-array/
via @lzomedia #developer #freelance #web #lzomedia.com
No comments:
Post a Comment