列表视图上的三元操作在nativescript上不起作用

列表视图上的三元操作在nativescript上不起作用,nativescript,Nativescript,列表视图上绑定元素的三元操作无效 我试着向印度而不是西班牙展示,但没有成功。如果不可能,那么如何实现呢?请确保为您的操作员添加额外的=。看起来你实际上是在指定印度作为你在那里拥有的每一处房产的名称 <FlexboxLayout flexDirection="row" class="list-group-item"> <Image src="{{ imageSrc }}" class="thumb img-circle" /> <Label text

列表视图上绑定元素的三元操作无效


我试着向印度而不是西班牙展示,但没有成功。如果不可能,那么如何实现呢?

请确保为您的操作员添加额外的
=
。看起来你实际上是在指定印度作为你在那里拥有的每一处房产的名称

<FlexboxLayout flexDirection="row" class="list-group-item">
    <Image src="{{ imageSrc }}" class="thumb img-circle" />
    <Label text="{{ name === 'Spain' ? 'INDIA' : name }}" class="list-group-item-heading"
        verticalAlignment="center" style="width: 60%" />
</FlexboxLayout>

您还可以避免使用大括号和绑定语法。它更干净

<FlexboxLayout flexDirection="row" class="list-group-item">
    <Image [src]="imageSrc" class="thumb img-circle" />
    <Label [text]="name === 'Spain' ? 'INDIA' : name" class="list-group-item-heading"
        verticalAlignment="center" style="width: 60%" />
</FlexboxLayout>

三元操作将根据条件工作。如果它的结果是正确的或错误的,那么它将正常工作。所以,在编写条件语句时必须非常小心。因为在代码中,而不是==它被写入=。这就是它不起作用的原因

<FlexboxLayout flexDirection="row" class="list-group-item">
    <Image src="{{ imageSrc }}" class="thumb img-circle" />
    <Label text="{{ name === 'Spain' ? 'INDIA' : name }}" class="list-group-item-heading"
        verticalAlignment="center" style="width: 60%" />
</FlexboxLayout>
<FlexboxLayout flexDirection="row" class="list-group-item">
    <Image [src]="imageSrc" class="thumb img-circle" />
    <Label [text]="name === 'Spain' ? 'INDIA' : name" class="list-group-item-heading"
        verticalAlignment="center" style="width: 60%" />
</FlexboxLayout>