zoukankan      html  css  js  c++  java
  • 微信小程序:picker组件实现下拉框效果

    一、wxml中代码

    <view class="in_order_Param">
                <text>状态:</text>
                <picker mode="selector" bindchange="bindPickerChange" value="{{listQuery.status}}range="{{array}}">
                    <input placeholder="状态" name="status" value="{{name}}" bindinput="handleinput" data-name="status" style=" 90%"/>
                </picker>
            </view>

    mode值为selector,即普通模式。注意:选择某一项后,提交的是索引,即listQuery.status为索引值,为数值。选择后触发change事件。

    二、js中的代码

    data: {
            listQuery: {
              page: 1, // 页码
              limit: 5, // 个数
            },
            array: ['新建', '已发货', '已收货', '退货','已入库','已备货','已确认','部分退货','已作废'], // 0.新建1.已发货2.已收货3.退货4.已入库5.已备货6.已确认7.部分退货9.已作废
            name: ''
          },
          onLoad: function () {
            this.getSupplyNoteList(true);
          },
    getSupplyNoteList: function(isRefresh){
            var that = this;
            console.log(that.data.listQuery);
              request.postParam("/api/supply/list",that.data.listQuery,function(res){
                  wx.hideLoading();
                  console.log(res)
                  。。。。。省略。。。。。
            });
        },
    bindPickerChange: function(e) {
          // console.log(e);
          this.setData({
            name: this.data.array[e.detail.value],
            'listQuery.status': e.detail.value == 8 ? (parseInt(e.detail.value) + 1)  : e.detail.value
          })
          console.log('picker发送选择改变,显示值为', this.data.listQuery.status)
        },
     

    触发change事件后调用bindPickerChange方法,方法中将e中传递过来的索引值转换为状态对应的中文,这样页面就显示出了状态的中文。同时修改listQuery.status的值,因为状态“已作废”的索引不是8,而是9,所以需要经过处理,然后再发起请求。

    页面效果如下:

  • 相关阅读:
    go get golang.org被墙问题解决
    golang的cms
    一次composer错误使用引发的思考
    colly源码学习
    IdentityServer4 禁用 Consent screen page(权限确认页面)
    Visual Studio for Mac 初体验
    ASP.NET Core 简单实现七牛图片上传(FormData 和 Base64)
    ASP.NET Core 注入和获取 AppSettings 配置
    ASP.NET Core 使用 Hangfire 定时任务
    Repository 简化实现多条件查询
  • 原文地址:https://www.cnblogs.com/zwh0910/p/14031938.html
Copyright © 2011-2022 走看看