收藏
回答

为什么checkbox-group多选不能传值到另一wxml页面?

A.wxml

  
viewclass"weui-cells weui-cells_after-title">
        viewclass"weui-cells__title">(选用第二项需备注)</view
            checkbox-groupbindchange"checkboxChange">
                labelclass"weui-cell weui-check__label"wx:for"{{checkboxItems}}"wx:key"value">
                    checkboxclass"weui-check"value"{{item.value}}"checked"{{item.checked}}"

                    viewclass"weui-cell__hd weui-check__hd_in-checkbox">
                        iconclass"weui-icon-checkbox_circle"type"circle"size"43"wx:if"{{!item.checked}}"></icon
                        iconclass"weui-icon-checkbox_success"type"success"size"33"wx:if"{{item.checked}}"></icon
                    </view
                    viewclass"weui-cell__bd">{{item.name}}</view
                </label
            </checkbox-group
            
        </view



A.js

 checkboxItems: [
      { name: '是否匹配3', value: '3' },
     
      { name: '是否匹配4', value: '4' },
    
    ],
  checkboxChange: function (e) {
    console.log('checkbox发生change事件,携带value值为:', e.detail.value);

    var checkboxItems = this.data.checkboxItems, values = e.detail.value;
    
    for (var i = , lenI = checkboxItems.length; i < lenI; ++i) {
      checkboxItems[i].checked = false

      for (var j = , lenJ = values.length; j < lenJ; ++j) {
        if (checkboxItems[i].value == values[j]) {
          checkboxItems[i].checked = true
          break
        }
      }
    };
    this.setData({
      checkboxItems: checkboxItems
    });
    wx.setStorageSync('box', e.detail.value);
   // wx.setStorageSync('boxs',checkboxItems);
  },


B.wxml

view类:  {{box1}} </view
view类:  {{box2}} </view
view类:  {{box3}} </view
view类:  {{boxs}} </view



B.js


    var checkboxItems = this.data.checkboxItems
    var box = wx.getStorageSync('box');
    var boxs = wx.getStorageSync('box', checkboxItems);
    console.log("预约复选显示", box);
    if(box == 3 ){
      console.log("预约单选dian1");
      var box1 = '单选3'
    };
    if (boxs == 4 ) {
      console.log("预约dan选DAN2");
      var box2 = '单选4'

      if (boxs == 3,4 ) {
        console.log("预约复选quanzhong2");
        var box3 = '全部9'


      };


单选(box=3)或者(boxs=4)都可以正常传值。

但是每次单选时,都会执行:
                  if (boxs == 3,4 ) {
                          console.log("预约复选quanzhong2");
                          var box3 = '全部9'
                  
                  
                        };


请问大佬这是什么情况?怎么才能实现只有当复选(boxs=3,4)时,才执行复选的if??

回答关注问题邀请回答
收藏

1 个回答

  • Why not?
    Why not?
    2020-01-04

    复选的时候是个数组吧,你拿来当成字符串比较了?

    2020-01-04
    有用
    回复 1
    • mediocre person
      mediocre person
      2020-01-04
      嗯嗯,怎么才能只执行复选的if语句呢?
      2020-01-04
      回复
登录 后发表内容
问题标签