L19862185390 2022-02-17 22:13 采纳率: 100%
浏览 15
已结题

handleItemTap(e) 里的rightContent是空数组

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

```xml
<view class="cates">
    <SearchInput ></SearchInput>
    <view class="cates-container"> 
        <!--左侧菜单-->
     <scroll-view class="left-menu" scroll-y="{{true}}">
     <view class="menu-item {{index===currentIndex?'active':'' }} "wx:for="{{leftMenuList}}" wx:key="id" bindtap="handleItemTap" data-id="{{item.id}}" data-index="{{index}}" >{{item.name}}</view>
     </scroll-view>
        <!--右侧商品内容-->
        <scroll-view class="right-content" scroll-top="{{scrollTop}}" scroll-y="{{true}}">
            <view class="goods-group"  >
                <view class="goods-list" wx:if="{{rightContent.length > 0}}">
                   <navigator  wx:for="{{rightContent}}" wx:for-item="item1" wx:for-index="index1" wx:key="id">
                       <view class="goods-image"><image class="" src="{{item1.icon}}" mode="widthFix" /></view>
                       <view class="goods-name" >{{item1.name}}</view>
                    </navigator>
                </view>
            </view>
        </scroll-view>
    </view>
</view>

```javascript
import {request} from "../../request/index.js";
const WXAPI = require('apifm-wxapi');
const app = getApp();
WXAPI.init('jilong456')

Page({
    data: {
//左侧的菜单数据 
leftMenuList:[],
//右侧的菜单数据
rightContent:[],
//被点击的左侧菜单
currentIndex: 0,
    },
    Cates:[],
    onLoad: function (options) {
     this.getCates();
    },
    //获取分类数据
    getCates(){
      WXAPI.goodsCategory().then(res => app.handleDestruction(res))
      .then((data) => {
          //构造左侧数据
          let leftMenuList = data.filter(v =>v.level==1)
      this.setData({
          leftMenuList,
        })
      });
      //构造右侧数据
      WXAPI.goodsCategory().then(res => app.handleDestruction(res))
      .then((data) => {
      let rightContent = data.filter(v=>v.level==2)
      this.setData({
       rightContent,
      })
      })
    },
    //左侧菜单的点击事件
    handleItemTap(e){
      let id = null;
      let index = 0;
      if (e) {
        if (!e.currentTarget) {
          id = e.id;
          index = e.index;
        } else {
          id = e.currentTarget.dataset.id;
          index = e.currentTarget.dataset.index;
        }
      }
      let rightContent = this.Cates.filter(v => v.pid == id);
      this.setData({
        currentIndex: index,
        rightContent,
        scrollTop: 0,
      })
     
      console.log(rightContent)
      },
     
    onReady: function () {

    },

    
    onShow: function () {

    },

    onHide: function () {

    },

   
    onUnload: function () {

    },

    
    onPullDownRefresh: function () {

    },

   
    onReachBottom: function () {

    },

   
    onShareAppMessage: function () {

    }
})



```

  • 写回答

1条回答 默认 最新

  • 喵喵学姐 2022-02-18 10:07
    关注

    Cates自始至终都是空数组,所以rightContent也是空数组

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 2月26日
  • 已采纳回答 2月18日
  • 创建了问题 2月17日