gpt4 book ai didi

javascript - AngularJS ng-重复 : show data only when data is not false

转载 作者:行者123 更新时间:2023-11-29 19:27:18 24 4
gpt4 key购买 nike

我在应用程序中使用 angular,我在我的 html 页面中显示数据,如下所示:

<div class="orderspresent" ng-cloak="">
<div class="roworders" ng-controller="allorders" >
<div class="col-md-3" ng-repeat= "o in orders">
<div class="sm-st clearfix">
<div class="sm-st-info">
<i class="fa fa-square"></i>
<span>{{o.customerName}}</span>
<p>1 minutes</p>
<ul>
<li ng-repeat= "details in o.details">
{{details.aantal}} x {{details.productTitle}}
<br>+ {{details.extras}}
</li>
</ul>
</div>
</div>
</div>
</div>
</div>

JSON 示例

   {
"49": {
"orderID": 49,
"customerID": 61,
"orderDate": "2015-05-06 10:03:05",
"orderDeliveryDate": "2015-05-06",
"orderStatus": "prepare",
"customerName": "Caroline",
"details": [
{
"orderdetailID": 83,
"productTitle": "Sexy Teacher",
"productPrijs": 4,
"aantal": 2,
"extras": "Extra syrup, Soya milk",
"extrasPrice": 0.6
},
{
"orderdetailID": 84,
"productTitle": "Caramel Macchiato",
"productPrijs": 5.2,
"aantal": 2,
"extras": false,
"extrasPrice": 0
},
{
"orderdetailID": 85,
"productTitle": "The Coach",
"productPrijs": 3,
"aantal": 3,
"extras": false,
"extrasPrice": 0
},
{
"orderdetailID": 86,
"productTitle": "The Virgin",
"productPrijs": 3.2,
"aantal": 5,
"extras": "Extra syrup, Whipped cream, 3 espresso shots",
"extrasPrice": 2.4
}
]
}
}

正如您在上方的 JSON 示例中所见,{{details.extras}} 值有时可能为假。所以现在当我使用 {{details.extra}} 时,它在我的 html 中显示为 false。但在那种情况下,我不想在那里显示任何内容。只是空白。

如何实现?

最佳答案

最好的选择是使用 ng-if :

<span ng-if="details.extras">+ {{details.extras}}<span>

ng-if 从 DOM 中删除节点。更小的 DOM - 更快的操作。

关于javascript - AngularJS ng-重复 : show data only when data is not false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30074057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com