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

 

posted @ 2016-02-04 11:36  FengLu-1  阅读(7812)  评论(0编辑  收藏  举报