当前位置:   article > 正文

微信小程序,循环下拉列表,点击时只展开其中一个_微信小程序for循环中的下拉菜单

微信小程序for循环中的下拉菜单

微信小程序,循环下拉列表,点击时只展开其中一个

这是效果

1.wxml

  1. <!-- bigwarp -->
  2. <view class="dewarp">
  3. <view class='com-selectBox' wx:for="{{detil}}" wx:for-item="item" wx:key="">
  4. <view class='com-sContent' bindtap='showList' data-id='{{item.repairitemsetid}}'>
  5. <view class='com-sTxt'>{{item.repairitemsetname}}</view>
  6. <view class="caricon">
  7. <image data-id='{{id}}' src="../../images/icon/carDetails1.png" class='com-sImg {{imgshow&&"select_img_rotate"}}' ></image></view>
  8. </view>
  9. <view class=" {{item.isShow?'show':'hide'}}" >
  10. <!-- -->
  11. <view wx:for="{{notice}}" wx:for-item="item" wx:key="" class='com-sItem'>
  12. <i-row >
  13. <!-- -->
  14. <i-col span="15" i-class="">
  15. <view class="cb">
  16. <checkbox-group bindchange="checkboxChange">
  17. <label class="checkbox">
  18. <checkbox value="{{item.name}}" checked="{{item.checked}}"/>{{item.repairitemname}}
  19. </label>
  20. </checkbox-group>
  21. </view>
  22. </i-col>
  23. <!-- -->
  24. <i-col span="9" i-class="carmoney">
  25. <view class="carpropectdo">
  26. <view class="carpropectdollows"><input></input></view>
  27. </view>
  28. </i-col>
  29. </i-row>
  30. </view>
  31. <!-- -->
  32. </view>
  33. </view>
  34. </view>
  35. <!-- end -->

2,wxss

  1. /* bigwarp */
  2. .rotateRight{
  3. transform: rotate(180deg)
  4. }
  5. .com-selectBox{
  6. width: 90%;
  7. margin: 0 auto;
  8. }
  9. .com-sContent{
  10. /* border: 1px solid #e2e2e2; */
  11. background: white;
  12. font-size: 16px;
  13. line-height: 30px;
  14. box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(85, 85, 85, 0.13);
  15. border-radius: 20rpx;
  16. height: 100rpx;
  17. margin-top: 40rpx;
  18. display: flex;
  19. justify-content: space-between;
  20. align-items: center;
  21. }
  22. .com-sImg{
  23. width: 16px;
  24. height: 9px;
  25. }
  26. .caricon{
  27. /* border: 1px solid black; */
  28. right: 10px;
  29. display: flex;
  30. justify-content: center;
  31. align-items: center;
  32. width: 15%;
  33. height: 100%;
  34. }
  35. .com-sTxt{
  36. width: 15%;
  37. /* border: 1px solid black; */
  38. height: 100%;
  39. display: flex;
  40. justify-content: center;
  41. align-items: center;
  42. }
  43. .com-sList{
  44. box-shadow: 0rpx 2rpx 2rpx 2rpx rgba(85, 85, 85, 0.13);
  45. width: inherit;
  46. position: absolute;
  47. box-sizing: border-box;
  48. z-index: 3;
  49. max-height: 120px;
  50. overflow: auto;
  51. }
  52. .com-sItem{
  53. height: 55px;
  54. line-height: 35px;
  55. padding: 0 6px;
  56. text-align: left;
  57. overflow: hidden;
  58. text-overflow: ellipsis;
  59. white-space: nowrap;
  60. font-size: 14px;
  61. }
  62. .com-sItem:first-child{
  63. border-top: none;
  64. }
  65. .dewarp{
  66. margin: 0 auto;
  67. width: 100%;
  68. }
  69. .carpropectdo{
  70. padding: 10px 10px;
  71. }
  72. .carpropectdollows{
  73. width:90%;
  74. border: 1rpx solid #D1D1D1;
  75. display: flex;
  76. justify-content: center;
  77. align-items: center;
  78. padding: 0 10rpx;
  79. color: #999999;
  80. font-size: 32rpx;
  81. height: 27px;
  82. }
  83. .checkbox checkbox{
  84. padding:0 5rpx;
  85. }
  86. .checkbox{
  87. font-size: 13px;
  88. }
  89. .cb{
  90. padding: 13rpx 5rpx;
  91. }
  92. .hide{
  93. display: none;
  94. }
  95. .select_img_rotate{
  96. transform:rotate(180deg);
  97. }
  98. /* end */

3.wxjs

  1. // pages/a/a.js
  2. var app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. },
  9. /**
  10. * 生命周期函数--监听页面加载
  11. */
  12. onLoad: function (options) {
  13. app.login().then(() => {
  14. this.carDetailtitle(),
  15. this.carDetail()
  16. })
  17. },
  18. showList(e) {
  19. let index = 0;
  20. let arrayItem = this.data.detil;//获取循环数组对象
  21. for (let item of arrayItem) {
  22. //如果当前点击的对象id和循环对象里的id一致
  23. if (item.repairitemsetid == e.currentTarget.dataset.id ) {
  24. //判断当前对象中的isShow是否为truetrue为显示,其他为隐藏)
  25. if (arrayItem[index].isShow == "" || arrayItem[index].isShow == undefined) {
  26. arrayItem[index].isShow = "true"
  27. imgshow: !this.data.imgshow
  28. } else {
  29. arrayItem[index].isShow = ""
  30. imgshow: !this.data.imgshow
  31. }
  32. }
  33. index++;
  34. }
  35. //将数据动态绑定
  36. this.setData({
  37. detil: arrayItem
  38. })
  39. },
  40. carDetailtitle(down) {
  41. var a = app.data
  42. libs.post('接口', {
  43. miniopenid: a.openid,
  44. carplate: a.carplate
  45. }, down).then(res => {
  46. console.log(JSON.parse(res))
  47. this.setData({
  48. detil: JSON.parse(res),
  49. })
  50. })
  51. },
  52. carDetail(down) {
  53. var a = app.data
  54. libs.post('接口', {
  55. miniopenid: a.openid,
  56. carplate: a.carplate,
  57. rcid: 7
  58. }, down).then(res => {
  59. console.log(JSON.parse(res))
  60. this.setData({
  61. notice: JSON.parse(res),
  62. })
  63. })
  64. },
  65. checkboxChange: function (e) {
  66. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  67. },
  68. /**
  69. * 生命周期函数--监听页面初次渲染完成
  70. */
  71. onReady: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面显示
  75. */
  76. onShow: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面隐藏
  80. */
  81. onHide: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面卸载
  85. */
  86. onUnload: function () {
  87. },
  88. /**
  89. * 页面相关事件处理函数--监听用户下拉动作
  90. */
  91. onPullDownRefresh: function () {
  92. },
  93. /**
  94. * 页面上拉触底事件的处理函数
  95. */
  96. onReachBottom: function () {
  97. },
  98. /**
  99. * 用户点击右上角分享
  100. */
  101. onShareAppMessage: function () {
  102. }
  103. })

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/77093
推荐阅读
相关标签