html - How to avoid populating a table in a repetitive manner? -


right have table looks this:

enter image description here

the html table looks (i included brief snippet because rest of html looks same):

<table class="table table-bordered table-condensed">                                 <tr>                                     <th>days</th>                                     <th>date</th>                                     <th>calories</th>                                     <th>happiness</th>                                     <th>hunger</th>                                     <th>motivation</th>                                 </tr>                                 <tr>                                     <td>1</td>                                     <td id="day">{{dayarray[0]}}</td>                                     <td id="calorie">{{caloriearray[0]}}</td>                                     <td><input placeholder="0" /></td>                                     <td><input placeholder="0" /></td>                                     <td><input placeholder="0" /></td>                                 </tr>                                 <tr>                                     <td>2</td>                                     <td id="day">{{dayarray[1]}}</td>                                     <td id="calorie">{{caloriearray[1]}}</td>                                     <td><input placeholder="0" /></td>                                     <td><input placeholder="0" /></td>                                     <td><input placeholder="0" /></td>                                 </tr>                                 <tr>                                     <td>3</td>                                     <td id="day">{{dayarray[2]}}</td>                                     <td id="calorie">{{caloriearray[2]}}</td>                                     <td><input placeholder="0" /></td>                                     <td><input placeholder="0" /></td>                                     <td><input placeholder="0" /></td>                                 </tr>                                 <tr> 

i using array populate date because dependent on user chooses earlier on in page, date changes. same goes calories. using angularjs's data binding this.

does have idea of how change table's html make less repetitive? have heard anytime begin start copying , pasting things, it's sign you're writing bad code :(

use ng-repeat

<table class="table table-bordered table-condensed">    <tr>        <th>days</th>        <th>date</th>        <th>calories</th>        <th>happiness</th>        <th>hunger</th>        <th>motivation</th>   </tr>   <tr ng-repeat="day in dayarray">       <td>{{ $index + 1 }}</td>       <td id="day-{{$index}}">{{day}}</td>       <td id="calorie-{{$index}}">{{caloriearray[$index]}}</td>       <td><input placeholder="0" /></td>       <td><input placeholder="0" /></td>       <td><input placeholder="0" /></td>    </tr> 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -