欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

微信小程序 navbar实例详解

程序员文章站 2023-08-26 17:14:52
微信小程序 navbar实例详解 实现效果图: data typelist: [ { name: "日报", id: "1" }, {...

微信小程序 navbar实例详解

实现效果图:

微信小程序 navbar实例详解

data

typelist: [ 
  { name: "日报", id: "1" }, 
  { name: "周报", id: "2" }, 
  { name: "月报", id: "3" }, 
  { name: "目录", id: "4" }] 

js

 that.setdata({ 
  datevalue: util.formattime(new date()), //picker date 
  typelist: appinstance.typelist, 
  currenttypeid: "1" 
 }) 
 
 
//添加点击模板点击事件 
for (var i = 0; i < appinstance.typelist.length; i++) { 
 (function (item) { 
  pageobject['bind' + item.id] = function (e) { 
   this.setdata({ 
    currenttypeid: e.currenttarget.dataset.index 
   }) 
  } 
 })(appinstance.typelist[i]) 
} 



wxml

<dl class="menu"> 
 <block wx:for="{{typelist}}" wx:for-item="type" wx:key="{{index}}" wx:for-index="{{index}}"> 
 <dt bindtap="bind{{type.id}}" data-index="{{type.id}}" class="{{currenttypeid==type.id?'yescurrenttype':'nocurrenttype'}}">{{type.name}}</dt> 
 </block> 
</dl> 
<picker class="timepicker" mode="date" value="{{datevalue}}" bindchange="datepickerbindchange" start="1999-01-01" end="2999-12-12">时间:{{datevalue}} 
 <image class="selreportimg" src="../images/clock.png"></image> 
</picker> 

wxss

.timepicker { 
 width: 90%; 
 padding: 10rpx; 
 margin: auto; 
 border: 1px solid red; 
} 
 
.menu { 
 display: flex; 
 flex-direction: row; 
 align-items: flex-start; 
 justify-content: space-between; 
} 
 
dt { 
 width: 25%; 
 height: 100rpx; 
} 
 
.nocurrenttype { 
 height: 90rpx; 
 color: black; 
 padding-left: 30rpx; 
 border: 1px solid; 
 background-color: #c2c2c2; 
} 
 
.yescurrenttype { 
 color: black; 
 padding-left: 30rpx; 
} 

 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!