国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

小程序?qū)崿F(xiàn)分類頁

2024-05-06 15:36:59
字體:
供稿:網(wǎng)友

分類界頁面中,左邊是一級目錄,右邊是一級目錄對應(yīng)的二級目錄,根據(jù)這個需求,我們數(shù)據(jù)設(shè)計(jì)的結(jié)構(gòu)是數(shù)組嵌套數(shù)組,第一個數(shù)組包含一級目錄數(shù)據(jù),嵌套的數(shù)組包含的是二級目錄的數(shù)據(jù)。

主要知識:

1.定義本地json文件
2.本地文件引入
3.小程序列表渲染實(shí)現(xiàn)
4.解析本地json

定義本地的json數(shù)據(jù)源

該文件在page下面的data文件下面的categroryData.js中

//模擬json數(shù)據(jù) var categoryJson=[ { id: 'guowei', name: '果味', isChild: true, children: [ {  child_id: 1,  name: "果味" } ] }, { id: 'shucai', name: '蔬菜', isChild: true, children: [ {  child_id: 1,  name: "蔬菜" } ] }, { id: 'chaohuo', name: '炒貨', isChild: true, children: [ {  child_id: 1,  name: "炒貨" } ] }, { id: 'dianxin', name: '點(diǎn)心', isChild: true, children: [ {  child_id: 1,  name: "點(diǎn)心" } ] }, { id: 'ganguo', name: '干果', isChild: false, children: [] }, { id: 'clothes', name: '衣服', isChild: false, children: [] }, { id: 'bag', name: '包包', isChild: false, children: [] }, { id: 'woman', name: '女鞋', isChild: false, children: [] }, { id: 'mansport', name: '男鞋', isChild: false, children: [] }, { id: 'sports', name: '運(yùn)動鞋', isChild: false, children: [] }, { id: 'hzp', name: '化妝品', isChild: false, children: [] }, { id: 'life', name: '日常用品', isChild: false, children: [] }, { id: 'computer', name: '電腦', isChild: false, children: [] }, { id: 'phone', name: '手機(jī)', isChild: false, children: [] } ] //導(dǎo)出數(shù)據(jù) module.exports={ dataList:categoryJson }

顯示列表的頁面——categroy.wxml文件

<view class="main"> <view class="categroy-left"> <!-- 當(dāng)前項(xiàng)的id等于item項(xiàng)的id或者當(dāng)前的下標(biāo)等于item的下標(biāo)時,那個就是當(dāng)前狀態(tài)- --> <view wx:for="{{category}}" wx:key="index" data-id="{{item.id}}" data-index="{{index}}"  bindtap="switchTab"  class="cate-list {{curIndex === index?'active':''}}">{{item.name}}</view> </view> <scroll-view class="categroy-right" scroll-y="{{}}" scroll-into-view="{{toView}}" scroll-with-animation="true"> <view wx:if="{{category[curIndex].isChild}}"> <block wx:for="{{category[curIndex].children}}" wx:for-index wx:key="idx">  <view id="{{item.id}}" class="cate-box">  <view class="cate-title">  <text>{{item.name}}</text>  </view>  </view> </block>  </view> <!-- 若無數(shù)據(jù),則顯示暫無數(shù)據(jù) --> <view class='nodata' wx:else>該分類暫無數(shù)據(jù)</view> </scroll-view></view>

說明:

curIndex === index?'active':'' ,根據(jù)是否和一級目錄index相同,來判斷是否選中文字。相同執(zhí)行.cate-list.active樣式,不相同則執(zhí)行.cate-list樣式。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 昭通市| 鸡西市| 本溪| 化州市| 长汀县| 宜宾市| 宜黄县| 湘西| 旌德县| 三穗县| 威海市| 镇坪县| 湖州市| 宣城市| 孙吴县| 公主岭市| 临沂市| 扶余县| 南开区| 皮山县| 乐至县| 象州县| 亳州市| 陇南市| 如皋市| 周口市| 西乌| 金寨县| 白山市| 光泽县| 丽江市| 金阳县| 吉木萨尔县| 黄骅市| 太原市| 民勤县| 乌兰察布市| 年辖:市辖区| 洪泽县| 大庆市| 洪泽县|