亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時(shí)間:2019年07月12日 11:08:19   作者:smile@qingqing  
這篇文章主要為大家詳細(xì)介紹了小程序?qū)崿F(xiàn)好看的分類頁,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

主要知識(shí):

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)動(dòng)鞋',
 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)時(shí),那個(gè)就是當(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ù)是否和一級(jí)目錄index相同,來判斷是否選中文字。相同執(zhí)行.cate-list.active樣式,不相同則執(zhí)行.cate-list樣式。

將本地?cái)?shù)據(jù)引入到列表中——categroy.js文件

//引入本地的json數(shù)據(jù)
var jsonData=require("../../data/categroryData.js")
Page({
 data: {
 curIndex: 0,
 toView: 'guowei'
 },
 onLoad(){
 this.setData({
 //jsonData.dataList獲取data文件中categoryData.js中定義的Json數(shù)據(jù),并賦值給category
 category: jsonData.dataList
 })
 },
 switchTab(e){
 //將獲取到的item的id和數(shù)組的下表值設(shè)為當(dāng)前的id和下標(biāo)
 this.setData({
 toView: e.target.dataset.id,
 curIndex: e.target.dataset.index
 })
 } 
})

列表樣式——category.wxss文件

 .main{
 width:100%;
 height: 100%;
 }
 .categroy-left{
 float: left;
 width: 150rpx;
 height: 100%;
 overflow-y: auto;
 border-right: 1px solid #ddd;
 box-sizing: border-box;
 }
 .categroy-left .cate-list{
 height: 90rpx;
 line-height: 90rpx;
 text-align: center;
 border-left: 3px solid #fff;
 }
 .categroy-left .cate-list.active{
 color: #AB956D;
 border-color: #AB956D;
 }
 .categroy-right{
 float: right;
 width: 600rpx;
 height: 100%;
 }
 .cate-box{
 height: 100%;
 padding:40rpx;
 box-sizing: border-box;
 }
 .cate-title{
 position: relative;
 height: 30rpx;
 line-height: 30rpx;
 padding:30rpx 0 55rpx;
 text-align: center;
 color: #AB956D;
 font-size: 28rpx;
 }
 .cate-title::before{
 position: absolute;
 left: 130rpx;
 top: 43rpx;
 content: '';
 width: 70rpx;
 height: 4rpx;
 background: #AB956D;
 }
 .cate-title::after{
 position: absolute;
 right: 130rpx;
 top: 43rpx;
 content: '';
 width: 70rpx;
 height: 4rpx;
 background: #AB956D;
 }
 
 .nodata{
 font-size: 14px;
 text-align: center;
 color: #AB956D;
 margin-top: 100px;
 }

效果圖

好啦,大功告成!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • antd designable平臺(tái)的組件拖拽功能實(shí)現(xiàn)代碼

    antd designable平臺(tái)的組件拖拽功能實(shí)現(xiàn)代碼

    這篇文章主要介紹了antd designable平臺(tái)的組件拖拽功能實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
    2024-07-07
  • JavaScript復(fù)制變量三種方法實(shí)例詳解

    JavaScript復(fù)制變量三種方法實(shí)例詳解

    這篇文章主要介紹了JavaScript復(fù)制變量三種方法實(shí)例詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • JavaScript 實(shí)現(xiàn) Tab 點(diǎn)擊切換實(shí)例代碼

    JavaScript 實(shí)現(xiàn) Tab 點(diǎn)擊切換實(shí)例代碼

    Tab 選項(xiàng)卡切換效果在現(xiàn)如今的網(wǎng)頁中,運(yùn)用的也是比較多的,包括點(diǎn)擊切換、滑動(dòng)切換、延遲切換、自動(dòng)切換等多種效果,在這篇博文里,我們是通過原生 JavaScript 來實(shí)現(xiàn) Tab 點(diǎn)擊切換的效果。
    2017-03-03
  • BootStrap的兩種模態(tài)框方式

    BootStrap的兩種模態(tài)框方式

    bootstrap彈出層有多種觸發(fā)方式,以下是我用到的bootstrap的兩種模態(tài)框方式,需要的的朋友參考下吧
    2017-05-05
  • javascript實(shí)現(xiàn)狀態(tài)欄中文字動(dòng)態(tài)顯示的方法

    javascript實(shí)現(xiàn)狀態(tài)欄中文字動(dòng)態(tài)顯示的方法

    這篇文章主要介紹了javascript實(shí)現(xiàn)狀態(tài)欄中文字動(dòng)態(tài)顯示的方法,涉及JavaScript基于時(shí)間函數(shù)動(dòng)態(tài)操作頁面元素屬性的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10
  • js 代碼優(yōu)化點(diǎn)滴記錄

    js 代碼優(yōu)化點(diǎn)滴記錄

    這次項(xiàng)目中有一個(gè)功能,頻繁使用switch語句,代碼優(yōu)化的時(shí)候,將其換成數(shù)組
    2012-02-02
  • Javascript數(shù)組操作函數(shù)總結(jié)

    Javascript數(shù)組操作函數(shù)總結(jié)

    這篇文章主要給大家匯總介紹了Javascript數(shù)組操作函數(shù),需要的朋友可以參考下
    2015-02-02
  • 深入了解JavaScript詞法作用域

    深入了解JavaScript詞法作用域

    這篇文章主要介紹了JavaScript詞法作用域的相關(guān)資料,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-07-07
  • js點(diǎn)擊按鈕實(shí)現(xiàn)多張圖片循環(huán)切換

    js點(diǎn)擊按鈕實(shí)現(xiàn)多張圖片循環(huán)切換

    這篇文章主要為大家詳細(xì)介紹了js點(diǎn)擊按鈕實(shí)現(xiàn)多張圖片循環(huán)切換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • JavaScript多功能甘特圖組件jsGantt詳解

    JavaScript多功能甘特圖組件jsGantt詳解

    jsGantt是一個(gè)可定制的、靈活的、多語言的甘特圖組件,由原生 JavaScript構(gòu)建,它使用客戶端渲染以獲得快速的性能和動(dòng)態(tài)的交互性,非常適用于任何需要交互式時(shí)間線或時(shí)間表顯示的項(xiàng)目,本文就給大家介紹一下JavaScript多功能甘特圖組件jsGantt
    2023-07-07

最新評(píng)論