• Hbuilder MUI 选择器(Picker)设置默认选项


    mui 联动选择初始化很多人都遇到问题,就是setselectedvalue 不好用,实际上这个地方应该是有bug的

    所以只能用setselectedindex 来实现

    下面我是我的实现方式供大家参考:

    <script>
                (function($, doc) {
                    $.init();
                    $.ready(function() {
                        //-----------------------------------------
                        //                    //级联示例
                        var cityPicker3 = new $.PopPicker({
                            layer: 3
                        });
                        cityPicker3.setData(cityData3);
                        cityPicker3.pickers[0].setSelectedValue(130000);
                        var shi=cityPicker3.getSelectedItems()[0].children;
                        var val_shi=130200;
                        var val_xian=130204;
                        for(var i=0;i<shi.length;i++)
                        {                        
                            if(shi[i].value==val_shi)
                            {
                                cityPicker3.pickers[1].setSelectedIndex(i);
                                var xian=shi[i].children;
                                for(var j=0;j<xian.length;j++)
                                {
                                    if(xian[j].value==val_xian)
                                    {
                                        cityPicker3.pickers[2].setSelectedIndex(j);
                                    }
                                }
                            }                        
                        }
                        //cityPicker3.pickers[1].setSelectedIndex(2);
                        //cityPicker3.pickers[2].setSelectedIndex(3);
                        //cityPicker3.pickers[1].setSelectedValue(130205);
                        var showCityPickerButton = doc.getElementById('showCityPicker3');
                        var cityResult3 = doc.getElementById('cityResult3');
                        showCityPickerButton.addEventListener('tap', function(event) {
                            cityPicker3.show(function(items) {
                                cityResult3.innerText = "你选择的城市是:" + (items[0] || {}).text + " " + (items[1] || {}).text + " " + (items[2] || {}).text;
                                //返回 false 可以阻止选择框的关闭
                                //return false;
                            });
                        }, false);
                    });
                })(mui, document);
            </script>
    View Code
  • 相关阅读:
    JavaScript父子页面之间的相互调用
    把一个集合自定转成json字符串
    分页类与前台和后台的调用方法
    移动App测试实战—专项测试
    功能测试需求分析方法
    App弱网测试
    App常见产品问题及预防方法
    21天,搞定软件测试从业者必备的Linux命令
    Docker入门
    Linux核心-慧测课堂笔记
  • 原文地址:https://www.cnblogs.com/bindot/p/muipick.html
Copyright © 2020-2023  润新知