十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章主要介绍小程序下拉框组件的使用示例,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
10年积累的成都网站建设、网站设计经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先制作网站后付款的网站建设流程,更有红桥免费网站建设让你可以放心的选择与我们合作。
适用场景
1、省市三级联动
2、出生日期选择
3、性别选择
4、一般性的下拉选择等
一、省市三级联动使用
注意mode = region,以及value = “一维数组”
//.wxml当前选择:{{region[0]}},{{region[1]}},{{region[2]}}
二、出生日期选择
注意mode = date,以及value = “日期字符串”
{{date}}
三、性别选择
{{gender[index]}}
以上都需要在.js里设置相关初始变量!
var app = getApp(); data: { region:['湖南','长沙','岳麓'], date:'2010-10-10', gender:['男','女'], index:0 } bindViewEvent:function(e){ app.process(this,e); }
相关js类
//component.js const select = require('../component/select.js'); const upload = require('../component/upload.js'); class component{ constructor(com, that) { this.com = com; this.that = that; } //绑定下拉框选择事件 bindSelect(data){ let self = this; let mode = data.currentTarget.dataset.mode; let name = data.currentTarget.dataset.name; let picker = new select({ that: self.that, mode: mode, name: name }); picker.change(data.detail.value); } //点击事件,传递参数为e.currentTarget.dataset bindImageChoose(data){ //图片上传 this.uploader = new upload({ that: that, name: data.name, mode: data.mode, count: data.count || 9 }); this.uploader.choose(); } bindImageDel(data){ //图片上传 this.uploader = new upload({ that: that, name: data.name, mode: data.mode, count: data.count || 9 }); this.uploader.del(data.index); } } module.exports = component; //select.js /* * 下拉框对象 */ class picker{ constructor(data){ this.that = data.that; this.name = data.name || 'date'; this.mode = data.mode || 'selector'; } show(name,data){ let view = {}; view[name] = data; this.that.setData(view); } change(data){ let self = this; self.show(self.name, data); } } module.exports = picker; //upload.js class picUploader { constructor(data) { this.that = data.that; this.name = data.name; this.mode = data.mode || 1; this.count = this.model == 1 ? 1 : data.count || 9; } /* * 选择图片 */ choose() { const self = this; wx.chooseImage({ count: (self.count - self.that.data[self.name].length), sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function (res) { var tempFilePaths = res.tempFilePaths; self.append(tempFilePaths); } }) } /* * 显示图片 */ show() { let self = this; let view = {}; view[self.name] = self.that.data[self.name]; self.that.setData(view); } /* * 追加图片 */ append(data) { const self = this; for (let i = 0; i < data.length; i++) { self.that.data[self.name].push(data[i]); } self.show(); } /* * 删除图片 */ del(index) { let self = this; self.that.data[self.name].splice(index, 1); self.show(); } } module.exports = picUploader;
以上是“小程序下拉框组件的使用示例”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!