Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

angular - increase each value by 5 by each iteration using Map in Javascript?

I want to increase the map by 5 with each iteration.

   var newSet = new Set();

   newSet.value = trainingExercise.sets.length
     ? Math.max(...trainingExercise.sets.map((s) => s.value))
     : 0;

trainingExercise is variable like

{
exerciseId: 108
exerciseName: "Name",
isTest: true,
isTimed: false,
sets: [
{
 completed: false,
 isWarmup: false,
 note: "",
 pause: 0,
 reps: 0,
 value: 0
  }
 ]
}

So I want to set the values ??to start at 5 and increase with each iteration by for example 5

First iteration 5 second 10 , third 15......

Don't be confused trainingTemplateExercises is same values as trainingExercise...

<tr *ngFor="let set of trainingTemplateExercises.data.sets; index as i" [@enterAnimation]>
  <td style="width: 10%;">
    <div class="custom-control custom-switch">
      <input type="checkbox" class="custom-control-input" id="{{ 'warmUp' + trainingTemplateExercises.data.id + i }}" [(ngModel)]="set.isWarmup" />
      <label class="custom-control-label" for="{{ 'warmUp' + trainingTemplateExercises.data.id + i }}">{{ set.isWarmup ? "Da" : "Ne" }}</label>
    </div>
  </td>
  <td style="width: 18%;">
    <input type="number" [(ngModel)]="set.reps" name="reps" class="form-control radius" />
  </td>
  <td style="width: 18%;">
    <input type="number" [(ngModel)]="set.value" name="value" class="form-control radius" />
  </td>

  <td style="width: 18%;">
    <input type="number" [(ngModel)]="set.pause" name="pause" class="form-control radius" />
  </td>
  <td style="width: 31%;">
    <input type="text" [(ngModel)]="set.note" name="value" class="form-control radius" />
  </td>
  <td style="width: 5%;">
    <button type="button" class="btn btn-link text-danger px-0" (click)="removeSet(trainingTemplateExercises.data, i)">
      <img class="trash-icon" src="../../../assets/aplikacija/trash.png" width="30" height="30" alt="trash">
    </button>
  </td>
</tr>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
var newSet = new Set();

newSet.value = trainingExercise.sets.length
    ? Math.max(...trainingExercise.sets.map((s) => s.value+5))
        : 5;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...