当我从iPad / iPhone中的任何其他下拉列表中选择值时,我想打开下拉列表。

时间:2015-03-31 07:11:46

标签: javascript html iphone knockout.js drop-down-menu

我想在其他下拉菜单上打开一个下拉菜单。以下代码片段适用于浏览器,但它不适用于混合应用程序中的iPhone / iPad。

我们将不胜感激。请查看Code snippet on jsfiddle



 
   
    function ViewModel(choices, choice) {
        
        this.choices = ko.observableArray();
        this.choice = ko.observable();
        this.changedropDown=function(data,event){
            console.log("inside changedropDown");
            this.bindDropDown(event);
        };
        this.bindDropDown= function(event){
            //event.stopPropagation();
            console.log("insdie bindDropDown");
            this.choices(choices);
            setTimeout(function() {
                       showDropDown("xyz");
                       }, 500);
        };
    };
    
    var showDropDown = function (id) {
        console.log("inside showDropDown");
        var dropdown = document.getElementById(id);
        var event = document.createEvent('MouseEvents');
        event.initMouseEvent('mousedown', true, true, window);
        dropdown.dispatchEvent(event);
    };
    var choices = [{ id: 1, name: "one" },
                   { id: 2, name: "two" },
                   { id: 3, name: "three" }];
                   ko.applyBindings(new ViewModel(choices));

<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
    <select name="cars" data-bind="event:{change:function(data,event){changedropDown(data,event)}}">
        <option value="volvo">Volvo</option>
        <option value="saab">Saab</option>
        <option value="fiat">Fiat</option>
        <option value="audi">Audi</option>
    </select>
    <select id="xyz" data-bind="options: choices, optionsText: 'name', value: choice"></select>
&#13;
&#13;
&#13;

0 个答案:

没有答案