小程序(布局:左右栅栏布局)

(布局:左右栅栏布局)

写了个demo,抽取了一部分出来,觉得有必要记录一下,就贴下代码,有需要的同学可以直接复制用(可能想多了,哈哈,毕竟非常简单),需要注意点的是左边的选中状态的实现

class="columnitem {{item.id == currentSelectColumnID ? 'selcolumnitem' : ''}}"

因为数据是自己造的,写的比较随意,直接根据name取出对应栏的id,判断点击栏的id跟记录的id是否相等,相等则给他加个样式

效果图
图片发自简书App
1、布局内容

<!-- 容器视图 -->
<view class="bottomClassView">

  <!-- 左边 -->
  <scroll-view scroll-y="true" class="left-group">
    <view class="columnitem {{item.id == currentSelectColumnID ? 'selcolumnitem' : ''}}" wx:for="{{colunmitems}}" bindtap="changeitem" data-itemname="{{item.name}}" data-itemid="{{item.id}}" wx:key="{{index}}">{{item.name}}
    </view>
  </scroll-view>

  <!-- 右边 -->
  <scroll-view class="right-group" scroll-y="true">
    <view class="contentitem" wx:for="{{showContentDatas}}" wx:key="{{index}}">
      <image src=""></image>
      <view class="rightitemview">
        <view class="nameview">{{item.productname}}</view>
        <view class="labelview">
          <view class="labelvie-color">在途</view>
          <view class="labelvie-color">现有</view>
          <view class="labelvie-color">用完</view>
        </view>
      </view>
    </view>
  </scroll-view>
</view>
2、样式表
.bottomClassView {
  position: fixed;
  width: 100%;
  display: flex;
  bottom: 0rpx;
  top: 20rpx;
}

.left-group {
  width: 30%;
  margin-bottom: 0rpx;
  margin-top: 0rpx;
}

.left-group .columnitem {
  width: 100%;
  height: 80rpx;
  background-color: white;
  text-align: center;
  line-height: 80rpx;
  margin-bottom: 2rpx;
}
.left-group .selcolumnitem {
  background-color: gray;
  
}

.right-group {
  width: 70%;
  margin-bottom: 0rpx;
  margin-top: 0rpx;
}

.right-group .contentitem {
  width: 100%;
  height: 200rpx;
  display: flex;
  padding: 10rpx;
  align-items: center;
  background-color: white;
  margin-bottom: 2rpx;
}

.right-group .contentitem image {
  width: 150rpx;
  height: 150rpx;
  flex-basis: 150rpx;
  background-color: gray;
}

.right-group .contentitem .rightitemview {
  display: flex;
  flex-direction: column;
  margin: 20rpx;
  flex: 1;
}
.nameview{
  
}
.labelview {
  margin-top: 30rpx;
  display: flex;
  justify-content: space-around;
}
.labelview .labelvie-color{
  border-radius: 6rpx;
  color: white;
  background-color: gray;
  padding: 10rpx 15rpx;
}

3、本地数据
colunmitems: [{
      name: '全部',
      id: 1}, {
      name: '精油',
      id: 2 }, {
      name: '植物油',
      id: 3}, {
      name: '保健',
      id: 4 }, {
      name: '配件',
      id: 5 }, {
      name: '酱醋茶',
      id: 6 }, {
      name: '其他',
      id: 7 }],
    contentitemDatas: [{
      id: 1,
      name: '精油',
      data: [{
        productname: "茉莉精油"
      }, {
        productname: "玫瑰精油"
      }]
    }, {
      id: 2,
      name: '植物油',
      data: [{
        productname: "花生油"
      }, {
        productname: "菜籽油"
      }]
    }, {
      id: 3,
      name: '保健',
      data: [{
        productname: "枸杞"
      }, {
        productname: "保健药品"
      }, {
        productname: "药丸"
      }]
    }],
    showContentDatas: []
4、js相关代码
onLoad: function(options) {
    // 默认选择全部
    this.setDefaultdata();
  },
//设置默认数据
  setDefaultdata: function() {
    var myarray = [];
    for (var i in this.data.contentitemDatas) {
      var array = this.data.contentitemDatas[i].data;
      for (var j in array) {
        myarray.push(array[j]);
      }
    }
    this.setData({
      showContentDatas: myarray
    });
  }
//点击左边栏目,切换数据
changeitem: function(event) {
    var itemname = event.currentTarget.dataset.itemname;
    var itemid = event.currentTarget.dataset.itemid;
    this.setData({
      currentSelectColumnID: itemid
    })
    if (itemname == '全部') {
      this.setDefaultdata();
      return;
    }
    var myarray = [];
    for (var itemindex in this.data.contentitemDatas) {
      if (this.data.contentitemDatas[itemindex].name == itemname) {
        myarray = this.data.contentitemDatas[itemindex].data;
        break;
      }
    }
    this.setData({
      showContentDatas: myarray
    });
  }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 7,224评论 0 17
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,553评论 1 32
  • 那素卿是娘的姓名,娘的娘没有文化,却给娘起了这么动听的名字,每每读起萦绕舌边吐字缱绻,似有卿本佳人素洁若心。其实娘...
    蝶舞幽兰阅读 933评论 4 11
  • 砗磲作为一种有机宝石来说确实具有其独特性和美感,很多人也因为这种神秘的美而被深深的吸引。砗磲的颜色多样性,让很多人...
    砗磲在线阅读 523评论 0 0
  • “欢迎来到英雄联盟,敌军还有30秒到达战场,碾碎他们!” 这一声激动人心的开场词,已经伴随着我们走过了很多年。念了...
    geferrr阅读 285评论 0 0

友情链接更多精彩内容