<view>{{ticket.vehicle==="train"}}</view>
<view
wx:if='{{ticket.vehicle==="train"}}'
wx:for='{{ticket.price_list}}'
wx:key='index'
class='seat'
style='display: flex;'
wx:if='{{index < 3}}'
>
<view style='display: flex; font-size: 20rpx;'>
<view>{{item.name}}:</view>
<view>{{item.num}}</view>
</view>
</view>
部分字段:
'ticket' : {
"price": 2230,
"price_list": [
{
"cabin_code": "J",
"cabin_name": "公务舱",
"discount": 297,
"master": 76559,
"price": 6620
},
{
"cabin_code": "C",
"cabin_name": "公务舱",
"discount": 149,
"master": 76559,
"price": 3320
},
{
"cabin_code": "D",
"cabin_name": "公务舱",
"discount": 135,
"master": 76559,
"price": 3010
},
{
"cabin_code": "Q",
"cabin_name": "公务舱",
"discount": 130,
"master": 76559,
"price": 2900
},
{
"cabin_code": "Y",
"cabin_name": "经济舱",
"discount": 100,
"master": 76559,
"price": 2230
},
{
"cabin_code": "M",
"cabin_name": "经济舱",
"discount": 90,
"master": 76559,
"price": 2010
},
{
"cabin_code": "E",
"cabin_name": "经济舱",
"discount": 82,
"master": 76559,
"price": 1830
},
{
"cabin_code": "K",
"cabin_name": "经济舱",
"discount": 77,
"master": 76559,
"price": 1720
},
{
"cabin_code": "L",
"cabin_name": "经济舱",
"discount": 63,
"master": 76559,
"price": 1400
},
{
"cabin_code": "N",
"cabin_name": "经济舱",
"discount": 53,
"master": 76559,
"price": 1180
},
{
"cabin_code": "R",
"cabin_name": "经济舱",
"discount": 43,
"master": 76559,
"price": 960
},
{
"cabin_code": "S",
"cabin_name": "经济舱",
"discount": 35,
"master": 76559,
"price": 780
},
{
"cabin_code": "V",
"cabin_name": "经济舱",
"discount": 24,
"master": 76559,
"price": 540
}
],
"vehicle": "flight",
}
渲染结果:
冒号也被渲染了
我知道vue有这个问题,难道微信这边是 .replace('v', 'wx')?
别这样写啊,兄逮,vue现在 if 和 for写一层也会报错的。分开写吧,逻辑也清楚一些
首先小程序中for和if可以写在一起,但是你的wx:if写的是不是有点问题:
wx:if="{{ ticket.vehicle === "train" && index < 3 }}"
为什么不这样写呢,你上面写的这种wx:if的判断,在小程序中通过语法解析时候,会把你的第一个wx:if被第二个给覆盖掉。建议写法严谨一些。
这个是啥