鍍金池/ 問答/Python  HTML/ 小程序側(cè)邊tab切換,數(shù)據(jù)取到了,但是內(nèi)容沒對應(yīng)每個tabs數(shù)據(jù)內(nèi)容,請幫忙看下

小程序側(cè)邊tab切換,數(shù)據(jù)取到了,但是內(nèi)容沒對應(yīng)每個tabs數(shù)據(jù)內(nèi)容,請幫忙看下這是什么原因?

圖片描述

//index.js
//獲取應(yīng)用實(shí)例
const app = getApp();

// var goods = new Object();
var goodlist = [];//購物車數(shù)據(jù)
var goodtabsflag = [0, 0, 0, 0];//選項(xiàng)卡請求次數(shù)
var goodtabs = [1, 2, 3, 4];//選項(xiàng)卡請求次數(shù)
//放置4種商品列表的數(shù)據(jù)
var goods1 = [];
var goods2 = [];
var goods3 = [];
var goods4 = [];

var goodscount = 15;

function getGoodList(that, count, id) {//獲取選項(xiàng)卡內(nèi)容
    wx.request({
        url: 'https://m.septfar.com/api/book_combo/' + id + '/',

        method: 'GET',
        success: function (res) {
            if (id == 1) {
                for (let i in res.data) {
                    goods1.push(res.data[i])
                }
                that.setData({
                    goodListInfo3: goods1.splice(0, 5)
                })
            } else if (id == 2) {
                for (let i in res.data) {
                    goods2.push(res.data[i])
                }
                that.setData({
                    goodListInfo2: goods2.splice(0, 5)
                })
            } else if (id == 3) {
                for (let i in res.data) {
                    goods3.push(res.data[i])
                }
                that.setData({
                    goodListInfo1: goods3.splice(0, 5)
                })
            } else if (id == 4) {
                for (let i in res.data) {
                    goods4.push(res.data[i])
                }
                that.setData({
                    goodListInfo4: goods4.splice(0, 5)
                })
            }
        },
        fail: function (res) {
            console.log(res)
        }
    });
}

Page({
    data: {
        //用戶信息
        userInfo: {},
        hasUserInfo: false,
        canIUse: wx.canIUse('button.open-type.getUserInfo'),

        //商品列表 模板
        goods: {},

        //菜單導(dǎo)航
        currentTab: 0,
        tabs: ["套餐C", "套餐B", "套餐A", "單品"],
        activeIndex: 0,

        flag0: false,
        flag1: false,
        flag2: false,
        flag3: false,

        goodlist: [],

    },
    // 頁面打開
    onShow() {
        var that = this;
        that.setData({
            activeIndex: 0,
            goodListInfo1: [],
            goodListInfo2: [],
            goodListInfo3: [],
            goodListInfo4: [],
        })

        goodtabsflag = [0, 0, 0, 0];




        goods1 = [];
        goods2 = [];
        goods3 = [];
        goods4 = [];

        getGoodList(that, goodscount, 3)
        getGoodList(that, goodscount, 2)
        getGoodList(that, goodscount, 1)
        getGoodList(that, goodscount, 4)
        
        //獲取購物車本地緩存
        wx.getStorage({
            key: 'goods',
            success: function (res) {
                that.setData({
                    cartcount: res.data.num,
                    goods: res.data,
                    goodlist: res.data.goodlist
                })
            },
            fail: function (e) {
                that.setData({
                    cartcount: 0,
                    goods: {},
                    goodlist: []
                })
            },
        })
    },
    // 點(diǎn)擊切換tab切換
    tabClick: function (e) {
        var that = this;
        const thatid = e.currentTarget.id;
        that.setData({
            activeIndex: thatid //商品列表接口數(shù)組對應(yīng)的下標(biāo)
        });
    },

})
回答
編輯回答
野橘

goodListInfo4 好像不在data中。
只有在data中的數(shù)據(jù)才已渲染到頁面

2017年9月12日 01:09