前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >微信小程序picker选择器渲染json数据

微信小程序picker选择器渲染json数据

作者头像
王小婷
发布2021-06-29 10:12:16
1.2K0
发布2021-06-29 10:12:16
举报
文章被收录于专栏:编程微刊

json数据

代码语言:javascript
复制
{
    "msg": "查询成功",
    "code": 1,
    "data": [{
        "id": 1413,
        "organName": "广西化工有限公司"
    }, {
        "id": 1414,
        "organName": "安全环保部"
    }, {
        "id": 1415,
        "organName": "综合管理部"
    }, {
        "id": 1416,
        "organName": "财务部"
    }, {
        "id": 1417,
        "organName": "制造部"
    }, {
        "id": 1418,
        "organName": "设备专业"
    }, {
        "id": 1419,
        "organName": "仪表专业"
    }, {
        "id": 1420,
        "organName": "电气专业"
    }, {
        "id": 1421,
        "organName": "工艺专业"
    }, {
        "id": 1422,
        "organName": "调度管理"
    }, {
        "id": 1423,
        "organName": "气化装置"
    }, {
        "id": 1424,
        "organName": "甲醇装置"
    }, {
        "id": 1425,
        "organName": "醋酸装置"
    }, {
        "id": 1426,
        "organName": "乙二醇装置"
    }, {
        "id": 1427,
        "organName": "测试机构"
    }]
}

wxml

代码语言:javascript
复制
<form catchsubmit="confirmPublish">
    <view class="cu-form-group margin-top">
        <view class="title d-flex">被访部门
        </view>
        <picker  class="w-100 h-100 borderBottom flex-1 d-flex jc-start ai-center" style="height:100rpx;font-size: 30rpx;color: #555;" bindchange="bindPickerOrgan" value="{{index2}}" range="{{organarray}}">
            <view class="picker"  >
            {{organarray[visitOrganId]}}
            </view>
        </picker> 
    </view>
</form>

js

代码语言:javascript
复制
Page({
  data: {
    organarray: [],
    visitOrganId: 0,
  },
  //部门
  bindPickerOrgan: function (e) {
    console.log('picker发送选择改变,携带值为', e.detail.value)
    this.setData({
      visitOrganId: e.detail.value
    })
  },
  onLoad: function (options) {
    this.getOrgans()
  },
  //获取部门节点
  getOrgans: function () {
    var that = this;
    wx.request({
      url: 'http://192.1xxx8.4.xxx3:8093/cs-applet/subscribe/getOrgans',
      header: {
        'content-type': 'application/json',
      },
      method: 'get',
      success: res => {
        that.setData({
          organarray: (res.data.data || []).map(a => {
            return a.organName
          })
        })
      },
    })
  },
})

css

代码语言:javascript
复制
/* 确认发布的按钮 */

.btn1 {
  width: 90%;
  margin-top: 70rpx;
  margin-bottom: 70rpx;
  background-color: #09BB07;
  color: white;
  font-size: 33rpx;
  border-radius:13rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}
.d-flex {
display: flex;
}
.cu-form-group .title {
text-align: justify;
padding-right: 30rpx;
font-size: 30rpx;
position: relative;
height: 60rpx;
line-height: 60rpx;

}
.cu-form-group {
    background-color: var(--white);
    padding: 1rpx 30rpx;
    display: flex;
    align-items: center;
    min-height: 100rpx;
    justify-content: space-between;
}
.borderBottom {
  border-bottom: 1rpx solid #eee;
}

.ai-center {
align-items: center;

}
.jc-start {
justify-content: flex-start;

}
.flex-1 {
flex: 1;

}
.cu-form-group input {
    flex: 1;
    font-size: 30rpx;
    color: #555;
    padding-right: 20rpx;
}

效果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档