根据 Adonis.js 中数据库的结果更改 HTML 标签

Change HTML tag based on results from database in Adonis.js

我正在使用 Adonis 构建一个 node.js 应用程序,并根据查询中返回的列之一更改 html 的完成方式。如果该行在组列中有 'Y',我需要将其显示为 <h3>,否则需要将其显示为 <label> 以显示 <select>。知道检查这个的最佳方法吗?我尝试使用 @if,但出现以下错误 E_INVALID_EXPRESSION: Invalid expression <{{ question.Group }} == 'Y'> passed to (if) block。这是我的应用程序中的代码示例。

@each(question in questions)
        @if( {{ question.Group }} == 'Y')
          <h3> {{ question.Questions }}</h3>        
        @else
          <label for="{{ questions.SalesQuestionsKey }}"> {{ question.Questions }}, {{question.Group }}</label>
          <select type="text" name="{{ question.SalesQuestionsKey }}">
            <option value="na">NA</option>
            <option value="yes">Yes</option>
            <option value="no">No</option>
          </select>
        @endif
        <br />
@endeach

根据语法指南,您不需要在条件语句中插入。试试这个:

@each(question in questions)
    @if(question.Group == 'Y')
      <h3> {{ question.Questions }}</h3>        
    @else
      <label for="{{ questions.SalesQuestionsKey }}"> {{ question.Questions }}, {{question.Group }}</label>
      <select type="text" name="{{ question.SalesQuestionsKey }}">
        <option value="na">NA</option>
        <option value="yes">Yes</option>
        <option value="no">No</option>
      </select>
    @endif
    <br />
@endeach

[https://edge.adonisjs.com/docs/conditionals]