0

我在 Javascript mvc fake gym 应用程序中遇到了一些代码问题,我想根据 for 循环内的值更改图标的颜色,但颜色不会改变。图标在 for 循环外发生变化,但有谁知道我可以如何安排代码,以便图标的颜色会随着 for 循环内的每个值而变化

    ///Model
{
getTrend(id, weight) {
    const memberassessment = this.getMemberlist(id);
    const assess = memberassessment.assessments;

    for (let i = 0; i < assess.length; i++) {

        if (memberassessment.startingWeight > assess[assess.length - 1].weight) {
            const color = "green";
            return color;
        } else {
            const color = "red";
            return color;
        }

    }

},


///controller
index(request, response) {
    const memberlistId = request.params.id;
    const loggedInUser = accounts.getCurrentUser(request);

    const viewData = {
      title: 'Memberlist',
      memberlist: memberStore.getMemberlist(loggedInUser.id),
      bmi: memberStore.getBmi(loggedInUser.id),
      weightClass: memberStore.getWeightClass(loggedInUser.id),
      idealBodyWeight: memberStore.isIdealBodyWeight(loggedInUser.id),
      getTrend: memberStore.getTrend( loggedInUser.id, loggedInUser.weight),

    };
   // logger.info("BMI" + bmi);
    response.render('memberlist', viewData);
  },

///view
<tbody>
      {{#each memberlist.assessments}}
    <tr>
      <td></td>
      <td>{{weight}}
      </td>
      <td> {{chest}}   
      </td>
      <td> {{thigh}}
      </td>
      <td> {{upperArm}}
      </td>
      <td> {{waist}}
      </td>
      <td> {{hips}}
      </td>
      <td>     
        <a class="ui {{getTrend}} tag label"></a>
      </td>
      <td>
          <a href="/memberlist/{{../memberlist.id}}/deleteassessment/{{id}}" class="ui tiny red button">Delete
          <i class="icon trash"></i></a>
        </td>  
      <td> </td>    
</tr>
   {{/each}}   

  </tbody>

i want the icon to turn green or red using string
4

0 回答 0