使用mvc根据值更改图标颜色

时间:2019-08-22 09:06:42

标签: javascript html model-view-controller glitch-framework

我在Javascript MVC假健身房应用程序中的某些代码有问题,我想根据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

0 个答案:

没有答案