代码如下,

触发  tapFirstClass 事件时,定义的 sourceData、firstClassOpts、secondClassOpts 对象会变为空数组,为什么?


<template>

<view class="page">

<view class="class-wrap">

<view class="{{secondClassOpts.length>0?'class-first-wrap':'class-first-wrap-full'}} weui-cells weui-cells_after-title">

<view bindtap="tapFirstClass" data-firstClass="{{item}}" data-sourceData="{{sourceData}}" class="weui-cell" wx:for="{{firstClassOpts}}" wx:key="idx" wx:for-item="item">

<view class="weui-cell__bd">{{item.name}}</view>

</view>

</view>

<view wx:if="{{secondClassOpts.length > 0}}" class="class-second-wrap weui-cells weui-cells_after-title">

<view class="weui-cell" wx:for="{{firstClassOpts}}" wx:key="idx" wx:for-item="item">

<view class="weui-cell__bd">{{item.name}}</view>

</view>

</view>

</view>

</view>

</template>


<script>

import wepy from 'wepy';


export default class reportFirstStep extends wepy.page {

config = {

navigationBarTitleText: '第一步  选择大小类'

};


data = {

sourceData: [],

firstClassOpts: [],

secondClassOpts: []

};


onLoad() {

let that = this;


wx.request({

url:

'http://127.0.0.1:8080/class/findAll?typeId=1',

method: 'GET',

success: function(res) {

if (res.statusCode == 200 && res.data.code == 200) {

let opts = [];


// 获取大类

for (let i = 0; i < res.data.data.length; i++) {

if (res.data.data[i].parentClassId == 0) {

opts.push(res.data.data[i]);

}

}

that.setData({ sourceData: res.data.data });

that.setData({ firstClassOpts: opts });

}

}

});

}


tapFirstClass(event) {

let that = this;

debugger;

let firstClass = event.currentTarget.dataset.firstclass;

let sourceData = event.currentTarget.dataset.sourcedata;


let opts = [];

// 获取小类

for (let i = 0; i < sourceData.length; i++) {

if (sourceData[i].parentClassId ==

展开全部
收起
0回答
提交回答
  • 至过去的我

    2044人对此回答表示赞同

    我是未来的你,你现在是不是在年找寻小程序答案。你不要感觉诧异,给你来信原因,就是让你不在后悔。今天去学习如何推广小程序,相信......点击查看更多>
    发布于
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
咨询热线

13312967497

扫码添加业务即可随时咨询 还可领取小程序推广攻略

业务咨询: 13312967497
扫码咨询

扫码咨询套餐

回到顶部