微信小程序 WX:FOR问题
发布于 6 年前 作者 gang79 9065 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

<view class=“weui-form-preview”>

    <view class=“weui-form-preview__hd”>

        <view class=“weui-form-preview__item”>

            <view class=“weui-form-preview__label”>订单状态</view>

            <view class=“weui-form-preview__value_in-hd”>{{MSGCODE}}</view>

        </view>

    </view>

    <view class=“weui-form-preview__bd” wx:for="{{dataList.ROW}}" wx:key=“name”>

        <view class=“weui-form-preview__item”>

            <view class=“weui-form-preview__label”>票号</view>

            <view class=“weui-form-preview__value”>{{item.TICKETCODE}}</view>

        </view>

        <view class=“weui-form-preview__item”>

            <view class=“weui-form-preview__label”>姓名</view>

            <view class=“weui-form-preview__value”>{{item.REALNAME}}</view>

        </view>

        <view class=“weui-form-preview__item”>

            <view class=“weui-form-preview__label”>航班</view>

            <view class=“weui-form-preview__value”><text>{{item.FROMWHARFCNAME}} -> {{item.TOWHARFCNAME}}  \n {{item.DEPARTURESDATE}} {{item.DEPARTURESTIME}}</text></view>

        </view>

        <view class=“weui-form-preview__item”>

            <view class=“weui-form-preview__label”>其他信息</view>

            <view class=“weui-form-preview__value”><text>{{item.TICKETTYPECNAME}} {{item.CLIENTTYPECNAME}} {{item.CURRENCY}}{{item.PRICE}} \n {{item.SEATRANKCNAME}}:{{item.SEATNUMBER}} \n 销售渠道:{{item.AGENTCOMPANY}}</text></view>

        </view>

    </view>

当服务器返JSON的ROW下有两个人时,可以FOR循环(见第二个JASON),但是只有一个人时,FOR失败,没有渲染view (见第一个JASON)

(第一个JASON)

{

    “MSGCODE”: “06”, 

    “EMAIL”: "[email protected]", 

    “LANG”: “C”, 

    “TABLE”: {

        “ROW”: {

            “REFNO”: “1000000002ww5bu6u2d4210cuua226”, 

            “PASSENGER”: “1001”, 

            “PASSENGERID”: “0654”, 

            “TICKETCODE”: “116313981239”, 

            “DEPARTURESDATE”: “2018-11-12”, 

            “DEPARTURESTIME”: “08:30”, 

            “PRICE”: “120”, 

            “CURRENCY”: “RMB”, 

            “SEATRANKID”: “121”, 

            “VOYAGEROUTEID”: “156928956”, 

            “SEATNUMBER”: “53”, 

            “FROMPORTCNAME”: “蛇口”, 

            “FROMPORTTNAME”: “蛇口”, 

            “FROMPORTENAME”: “SHE KOU”, 

            “TOPORTCNAME”: “珠海”, 

            “TOPORTTNAME”: “珠海”, 

            “TOPORTENAME”: “ZHU HAI”, 

            “FROMWHARFCNAME”: “蛇口港”, 

            “FROMWHARFTNAME”: “蛇口港”, 

            “FROMWHARFENAME”: “She Kou”, 

            “TOWHARFCNAME”: “珠海九洲港”, 

            “TOWHARFTNAME”: “珠海九洲港”, 

            “TOWHARFENAME”: “Zhu Hai Jiu Zhou”, 

            “SEATRANKCNAME”: “普通位”, 

            “SEATRANKTNAME”: “普通位”, 

            “SEATRANKENAME”: “Economy Class”, 

            “CLIENTTYPECNAME”: “成人”, 

            “CLIENTTYPETNAME”: “成人”, 

            “CLIENTTYPEENAME”: “adult”, 

            “TICKETTYPECNAME”: “散客”, 

            “TICKETTYPETNAME”: “散客”, 

            “TICKETTYPEENAME”: “Walk-in”, 

            “TICKETTYPEREMARKCNAME”: { }, 

            “TICKETTYPEREMARKENAME”: { }, 

            “AGENTCOMPANY”: “XLM2”, 

            “TICKETREMARK1”: { }, 

            “TICKETREMARK2”: { }, 

            “FROMPORTCODE”: “SK”, 

            “TOPORTCODE”: “ZH”, 

            “VOYAGEREMARK”: { }, 

            “PRINTPRICE”: “120”, 

            “PRINTPRICETYPE”: “1”, 

            “FUELSURCHARGE”: “1”, 

            “PAYMENT”: “5”, 

            “ISJZ”: “02”, 

            “FROMBERTH”: { }, 

            “TOBERTH”: { }, 

            “QRCODE”: “116313981239108543395406540654SK^-ZH^2018111208306ZmI56eA5ZCbfDQ0MTUyMjE5OTkwMjI4MjE0WA==^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^1^0^^^1900010119000101^^^^^^^^^^^^^^^^^”, 

            “REALNAME”: “陈秀君”, 

            “IDNO”: “4415**********214X”

        }

    }

}

(第二个JASON)

{

    “MSGCODE”: “03”, 

    “EMAIL”: "[email protected]", 

    “LANG”: “C”, 

    “TABLE”: {

        “ROW”: [

            {

                “REFNO”: “1000000006xc7350033776”, 

                “PASSENGER”: “1001”, 

                “PASSENGERID”: “9921”, 

                “TICKETCODE”: “116313994197”, 

                “DEPARTURESDATE”: “2018-11-11”, 

                “DEPARTURESTIME”: “07:30”, 

                “PRICE”: “120”, 

                “CURRENCY”: “RMB”, 

                “SEATRANKID”: “33627656”, 

                “VOYAGEROUTEID”: “160485451”, 

                “SEATNUMBER”: “19”, 

                “FROMPORTCNAME”: “蛇口”, 

                “FROMPORTTNAME”: “蛇口”, 

                “FROMPORTENAME”: “SHE KOU”, 

                “TOPORTCNAME”: “珠海”, 

                “TOPORTTNAME”: “珠海”, 

                “TOPORTENAME”: “ZHU HAI”, 

                “FROMWHARFCNAME”: “蛇口港”, 

                “FROMWHARFTNAME”: “蛇口港”, 

                “FROMWHARFENAME”: “She Kou”, 

                “TOWHARFCNAME”: “珠海九洲港”, 

                “TOWHARFTNAME”: “珠海九洲港”, 

                “TOWHARFENAME”: “Zhu Hai Jiu Zhou”, 

                “SEATRANKCNAME”: “普通舱”, 

                “SEATRANKTNAME”: “普通艙”, 

                “SEATRANKENAME”: “Economy class”, 

                “CLIENTTYPECNAME”: “成人”, 

                “CLIENTTYPETNAME”: “成人”, 

                “CLIENTTYPEENAME”: “adult”, 

                “TICKETTYPECNAME”: “散客”, 

                “TICKETTYPETNAME”: “散客”, 

                “TICKETTYPEENAME”: “Walk-in”, 

                “TICKETTYPEREMARKCNAME”: { }, 

                “TICKETTYPEREMARKENAME”: { }, 

                “AGENTCOMPANY”: “XLM2”, 

                “TICKETREMARK1”: { }, 

                “TICKETREMARK2”: { }, 

                “FROMPORTCODE”: “SK”, 

                “TOPORTCODE”: “ZH”, 

                “VOYAGEREMARK”: { }, 

                “PRINTPRICE”: “120”, 

                “PRINTPRICETYPE”: “1”, 

                “FUELSURCHARGE”: “1”, 

                “PAYMENT”: “5”, 

                “ISJZ”: “02”, 

                “FROMBERTH”: { }, 

                “TOBERTH”: { }, 

                “QRCODE”: “116313994197108543759699219921SK^-ZH^2018111107306LWW5pmT55KHfDM1MDUwNDIwMDYwMTMwMjAyMA==^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^1^0^^^1900010119000101^^^^^^^^^^^^^^^^^”, 

                “REALNAME”: “赖晓璇”, 

                “IDNO”: “3505**********2020”

            }, 

            {

                “REFNO”: “1000000006xc7350033776”, 

                “PASSENGER”: “1002”, 

                “PASSENGERID”: “9921”, 

                “TICKETCODE”: “116373991198”, 

                “DEPARTURESDATE”: “2018-11-11”, 

                “DEPARTURESTIME”: “07:30”, 

                “PRICE”: “120”, 

                “CURRENCY”: “RMB”, 

                “SEATRANKID”: “33627656”, 

                “VOYAGEROUTEID”: “160485451”, 

                “SEATNUMBER”: “20”, 

                “FROMPORTCNAME”: “蛇口”, 

                “FROMPORTTNAME”: “蛇口”, 

                “FROMPORTENAME”: “SHE KOU”, 

                “TOPORTCNAME”: “珠海”, 

                “TOPORTTNAME”: “珠海”, 

                “TOPORTENAME”: “ZHU HAI”, 

                “FROMWHARFCNAME”: “蛇口港”, 

                “FROMWHARFTNAME”: “蛇口港”, 

                “FROMWHARFENAME”: “She Kou”, 

                “TOWHARFCNAME”: “珠海九洲港”, 

                “TOWHARFTNAME”: “珠海九洲港”, 

                “TOWHARFENAME”: “Zhu Hai Jiu Zhou”, 

                “SEATRANKCNAME”: “普通舱”, 

                “SEATRANKTNAME”: “普通艙”, 

                “SEATRANKENAME”: “Economy class”, 

                “CLIENTTYPECNAME”: “成人”, 

                “CLIENTTYPETNAME”: “成人”, 

                “CLIENTTYPEENAME”: “adult”, 

                “TICKETTYPECNAME”: “散客”, 

                “TICKETTYPETNAME”: “散客”, 

                “TICKETTYPEENAME”: “Walk-in”, 

                “TICKETTYPEREMARKCNAME”: { }, 

                “TICKETTYPEREMARKENAME”: { }, 

                “AGENTCOMPANY”: “XLM2”, 

                “TICKETREMARK1”: { }, 

                “TICKETREMARK2”: { }, 

                “FROMPORTCODE”: “SK”, 

                “TOPORTCODE”: “ZH”, 

                “VOYAGEREMARK”: { }, 

                “PRINTPRICE”: “120”, 

                “PRINTPRICETYPE”: “1”, 

                “FUELSURCHARGE”: “1”, 

                “PAYMENT”: “5”, 

                “ISJZ”: “02”, 

                “FROMBERTH”: { }, 

                “TOBERTH”: { }, 

                “QRCODE”: “116373991198108543759699219921SK^-ZH^2018111107306LWW6YeR5aCGfDM1MDUwMDE5NzkwODA4NTU1MA==^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^1^0^^^1900010119000101^^^^^^^^^^^^^^^^^”, 

                “REALNAME”: “赖金堆”, 

                “IDNO”: “3505**********5550”

            }

        ]

    }

}

  • 预期表现

只有一个人时,仍要渲染view (见第一个JASON)

1 回复

暂时自己想办法解决了,也许不是最好的思路。

<view class=“weui-form-preview”>

<view class=“weui-form-preview__hd”>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>订单状态</view>

<view class=“weui-form-preview__value_in-hd”>{{MSGCODE}}</view>

</view>

</view>

<view wx:if="{{dataList.ROW.length >1 }}" class=“weui-form-preview__bd” wx:for="{{dataList.ROW}}" wx:key=“ROW”><!-- 处理一个以上旅客时–>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>票号</view>

<view class=“weui-form-preview__value”>{{item.TICKETCODE}}</view>

</view>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>姓名</view>

<view class=“weui-form-preview__value”>{{item.REALNAME}}</view>

</view>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>航班</view>

<view class=“weui-form-preview__value”><text>{{item.FROMWHARFCNAME}} -> {{item.TOWHARFCNAME}}  \n {{item.DEPARTURESDATE}} {{item.DEPARTURESTIME}}</text></view>

</view>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>其他信息</view>

<view class=“weui-form-preview__value”><text>{{item.TICKETTYPECNAME}} {{item.CLIENTTYPECNAME}} {{item.CURRENCY}}{{item.PRICE}} \n {{item.SEATRANKCNAME}}:{{item.SEATNUMBER}} \n 销售渠道:{{item.AGENTCOMPANY}}</text>

</view>

</view>

</view>

<view wx:ifelse class=“weui-form-preview__bd” > <!-- 处理一个旅客时–>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>票号</view>

<view class=“weui-form-preview__value”>{{dataList.ROW.TICKETCODE}}</view>

</view>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>姓名</view>

<view class=“weui-form-preview__value”>{{dataList.ROW.REALNAME}}</view>

</view>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>航班</view>

<view class=“weui-form-preview__value”><text>{{dataList.ROW.FROMWHARFCNAME}} -> {{dataList.ROW.TOWHARFCNAME}}  \n {{dataList.ROW.DEPARTURESDATE}} {{dataList.ROW.DEPARTURESTIME}}</text></view>

</view>

<view class=“weui-form-preview__item”>

<view class=“weui-form-preview__label”>其他信息</view>

<view class=“weui-form-preview__value”><text>{{dataList.ROW.TICKETTYPECNAME}} {{dataList.ROW.CLIENTTYPECNAME}} {{dataList.ROW.CURRENCY}}{{dataList.ROW.PRICE}} \n {{dataList.ROW.SEATRANKCNAME}}:{{dataList.ROW.SEATNUMBER}} \n 销售渠道:{{dataList.ROW.AGENTCOMPANY}}</text>

</view>

</view>

</view>

</view>

回到顶部