如何评估视图中的表达式(How to evaluate expression in view)

编程入门 行业动态 更新时间:2024-10-25 06:22:48
如何评估视图中的表达式(How to evaluate expression in view)

在我的下面的代码中,我正在创建一个HTML table ,其table headers as First, second, Third row for each student table headers as First, second, Third和row for each student 。

根据得分,我需要将X放在相关列标题下的单元格中。

If score 10 than put X under First If score 9 than put X under second If score 8 than put X under third

我可以根据以上要求重新编写<td>{{score.Position}}</td> ,如下所示。

e.g. <td>{{score.Position}} == 10 ? X :'' </td> <td>{{score.Position}} == 9 ? X :'' </td>

码:

<table> <thead> <tr> <td></td> <td>First</td> <td>Second</td> <td>Tbhird</td> </tr> </thead> <tbody> <tr data-ng-repeat="student in Students"> <td>{{student.Name}}</td> <td>{{score.Position}}</td> </tr> </tbody> </table>

In my following code i am creating an HTML table with table headers as First, second, Third and than row for each student.

Depending upon score, I need to put X in cell under relevant column header. Example

If score 10 than put X under First If score 9 than put X under second If score 8 than put X under third

Can i re-write<td>{{score.Position}}</td> based on above requirement as following.

e.g. <td>{{score.Position}} == 10 ? X :'' </td> <td>{{score.Position}} == 9 ? X :'' </td>

Code:

<table> <thead> <tr> <td></td> <td>First</td> <td>Second</td> <td>Tbhird</td> </tr> </thead> <tbody> <tr data-ng-repeat="student in Students"> <td>{{student.Name}}</td> <td>{{score.Position}}</td> </tr> </tbody> </table>

最满意答案

做这个

<td>{{score.Position == 10 ? 'X' : ''}}</td>

或这个

<td><span data-ng-if="score.Position==10">X</span></td>

Do this

<td>{{score.Position == 10 ? 'X' : ''}}</td>

Or this

<td><span data-ng-if="score.Position==10">X</span></td>

更多推荐

本文发布于:2023-08-07 12:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表达式   视图   evaluate   expression   view

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!