微信小程序自定义select下拉选项框的方法_第1页
微信小程序自定义select下拉选项框的方法_第2页
微信小程序自定义select下拉选项框的方法_第3页
微信小程序自定义select下拉选项框的方法_第4页
微信小程序自定义select下拉选项框的方法_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第微信小程序自定义select下拉选项框的方法本文实例为大家分享了微信小程序自定义select下拉选项框的具体代码,供大家参考,具体内容如下

第一步:创建组件所需的文件

第二步:开始配置组件

select.json

{

"component":true,

"usingComponents":{

"select":"./select"

}

第三步:自定义组件样式及js

select.wxml

view

viewbindtap='selectToggle'

view{{nowText}}/view

imagesrc='../../public/image/index/jinru1@2x.png'

animation="{{animationData}}"/image

/view

viewwx:if="{{selectShow}}"

viewwx:for="{{propArray}}"data-index="{{index}}"wx:key=''bindtap='setText'{{item.text}}/view

/view

/view

select.wxss

.com-selectBox{

width:200px;

.com-sContent{

border:1pxsolid#e2e2e2;

background:white;

font-size:16px;

position:relative;

height:30px;

line-height:30px;

.com-sImg{

position:absolute;

right:10px;

top:11px;

width:16px;

height:9px;

transition:all.3sease;

.com-sTxt{

overflow:hidden;

text-overflow:ellipsis;

white-space:nowrap;

padding:020px06px;

font-size:14px;

.com-sList{

background:white;

width:inherit;

position:absolute;

border:1pxsolid#e2e2e2;

border-top:none;

box-sizing:border-box;

z-index:3;

max-height:120px;

overflow:auto;

.com-sItem{

height:30px;

line-height:30px;

border-top:1pxsolid#e2e2e2;

padding:06px;

text-align:left;

overflow:hidden;

text-overflow:ellipsis;

white-space:nowrap;

font-size:14px;

.com-sItem:first-child{

border-top:none;

}

select.js

Component({

/**

*组件的属性列表

*/

properties:{

propArray:{

type:Array,

}

/**

*组件的初始数据

*/

data:{

selectShow:false,//初始option不显示

nowText:"请选择",//初始内容

animationData:{}//右边箭头的动画

/**

*组件的方法列表

*/

methods:{

//option的显示与否

selectToggle:function(){

varnowShow=this.data.selectShow;//获取当前option显示的状态

//创建动画

varanimation=wx.createAnimation({

timingFunction:"ease"

})

this.animation=animation;

if(nowShow){

animation.rotate(0).step();

this.setData({

animationData:animation.export()

})

}else{

animation.rotate(180).step();

this.setData({

animationData:animation.export()

})

}

this.setData({

selectShow:!nowShow

})

},

//设置内容

setText:function(e){

varnowData=pArray;//当前option的数据是引入组件的页面传过来的,所以这里获取数据只有通过perties

varnowIdx=e.target.dataset.index;//当前点击的索引

varnowText=nowData[nowIdx].text;//当前点击的内容

//子组件触发事件

varnowDate={

id:nowIdx,

text:nowText

}

this.triggerEvent('myget',nowDate)

//再次执行动画,注意这里一定,一定,一定是this.animation来使用动画

this.animation.rotate(0).step();

this.setData({

selectShow:false,

nowText:nowText,

animationData:this.animation.export()

})

}

})

第四步:引入组件,传入组件所需数据

1、引入组件的页面的json文件中配置

{

"usingComponents":{

"Select":"../../components/select/select"

"navigationBarTitleText":""

}

2、引入组件的页面的wxml文件中配置

bind:myget=getDate对组件的事件进行监听

Selectprop-array='{{selectArray}}'bind:myget='getDate'/Select

3、引入组件的页面的js文件中配置

data:{

selectArray:[

{

"id":"01",

"text":"停车A区"

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论