SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vm.studentEnrollmentChecked = studentEnrollmentChecked;
  2.         function studentEnrollmentChecked(obj) {
  3.            
  4.             if(obj.checked) {
  5.  
  6.                 // verifica se obj.token existe dentro do array vm.form.students, caso não existir adicione a copia do obj junto ao vm.form.students
  7.  
  8.                 let studentIn = false;
  9.  
  10.                 angular.forEach(vm.form.students, function(objArr, key) {
  11.                     if(obj.token === objArr.token) {
  12.                         studentIn = true;
  13.                     }
  14.                 });
  15.  
  16.                 if(!studentIn) {
  17.                     vm.form.students.push(obj);
  18.                 }
  19.  
  20.             } else {
  21.                
  22.                 // verifica se existe no vm.form.students, caso existir remover o elemento do array vm.form.students
  23.  
  24.                 let studentIn = false;
  25.  
  26.                 angular.forEach(vm.form.students, function(objArr, key) {
  27.                     if(obj.token === objArr.token) {
  28.                         studentIn = true;
  29.                     }
  30.                 });
  31.  
  32.                 if(studentIn) {
  33.                     vm.form.students.splice(obj, 1);
  34.                 }
  35.  
  36.             }
  37.  
  38.             console.log('vm.form.students', vm.form.students);
  39.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top