简体   繁体   English

注释中的条件运算符floatval

[英]Conditional operators in comments floatval

I'm trying to make a conditional statement that renders an element depending on the floatval-value inside a property of an observableArray I'm iterating over 我正在尝试创建一个条件语句,根据observableArray属性中的floatval值呈现一个元素,我正在迭代

When I render the value itself it works: 当我渲染值本身时它起作用:

<span data-bind="text: stinger.points"></span>

For each in the observableArray I see the correct value, such as "3.2". 对于observableArray中的每一个,我看到正确的值,例如“3.2”。

Heres my actual statement, but none of them gets displayed in the computed html: 继承了我的实际陈述,但没有一个显示在计算的html中:

<!-- ko if: stinger.points  >1.49 && stinger.points <2.49 -->
    <div>1.5 - 2.48</div>       
<!-- /ko -->            
<!-- ko if: stinger.points  >2.49 && stinger.points <3.49 -->
    <div>2.5 - 3.48</div>
<!-- /ko -->    
<!-- ko if: stinger.points  >3.49 && stinger.points <4.49 -->
    <div>3.5 - 4.48</div>
<!-- /ko -->
<!-- ko if: stinger.points  >4.49 && stinger.points <5.1 -->
    <div>4.5 - 5</div>      
<!-- /ko -->
<!-- ko if: stinger.points  <0.1  -->
    <div >0</div>           
<!-- /ko -->

Or I could approach it like this: 或者我可以像这样接近它:

<div data-bind="visible: rating.points > 1.2 && rating.points < 3.4">between 1.3 - 3.5</div>

However, thats also not working, like above. 但是,这也不起作用,如上所述。

What am I doing wrong? 我究竟做错了什么? How to correct this? 怎么纠正这个?

When you use observable in the expression you have to unwrap it by adding (). 在表达式中使用observable时,必须通过添加()来解包它。 Update your code as follow: 更新您的代码如下:

<!-- ko if: stinger.points()  >1.49 && stinger.points() <2.49 -->
    <div>1.5 - 2.48</div>       
<!-- /ko -->            
<!-- ko if: stinger.points()  >2.49 && stinger.points() <3.49 -->
    <div>2.5 - 3.48</div>
<!-- /ko -->    
<!-- ko if: stinger.points()  >3.49 && stinger.points() <4.49 -->
    <div>3.5 - 4.48</div>
<!-- /ko -->
<!-- ko if: stinger.points()  >4.49 && stinger.points() <5.1 -->
    <div>4.5 - 5</div>      
<!-- /ko -->
<!-- ko if: stinger.points()  <0.1  -->
    <div >0</div>           
<!-- /ko -->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM