如何比较车把中数组的对象值?

问题描述 投票:0回答:0

这是我的对象数组

paper: [
  {
    "commentDate": "17-05-2023",
    "id": 1,
    "user_name": "xyz",
    "user_email": "[email protected]",
    "user_rating": 4,
    "user_review": "woow",
    "commentTime": "11:03:51",
    "paperId": 2,
    "userId": 3
  },
  {
    "commentDate": "17-05-2023",
    "id": 3,
    "user_name": "pqr",
    "user_email": "[email protected]",
    "user_rating": 5,
    "user_review": "very nice!",
    "commentTime": "11:17:57",
    "paperId": 2,
    "userId": 4
  }
]

在我的车把页面中,我想打印数据,例如

{{#each paper}}
     {{user_name}}
      {{user_email}
    
              
{{/each}}

现在我想在每个块下执行一些 if else 逻辑,如下所示

{{#each paper}}
     {{user_name}}
      {{user_email}
      

        if (user_rating == 4 ){
         } else if(user_rating == 3) {
         }else{
         }

              
{{/each}}

我该怎么做?请帮帮我 这是我的帮手

'math': function(v1, v2,options){
      if(v1 == v2){
        return options.fn(this);
      }
      else{
        return options.inverse(this);
      }
    }

我尝试了以下

   {{#each paper}}
         {{user_name}}
          {{user_email}
          {{#math user_rating 5}}
          //some logic
           {{else}}{{#math user_rating 4}}
             //some logic
            {{else}}
                //some logic
              {{/math}} 
                  
    {{/each}}

它说数学与每个都不匹配。 请帮助我。

node.js sequelize.js handlebars.js
© www.soinside.com 2019 - 2024. All rights reserved.