EasyUI combobox动态增加选择项

 有需求需要动态的为combobox增加可选项,后来解决方案如下

html如下

<select id="workerList"></select>

js 如下

 keyArray为数组 tips:此处forEach 不是都支持,火狐官网上有对此方法的修正现在直接将代码贴上,大家可以自行查阅

if (!Array.prototype.forEach) {  

            Array.prototype.forEach = function(callback, thisArg) {  

                var T, k;  

                if (this == null) {  

                    throw new TypeError(" this is null or not defined");  

                }  

                var O = Object(this);  

                var len = O.length >>> 0; // Hack to convert O.length to a UInt32  

                if ({}.toString.call(callback) != "[object Function]") {  

                    throw new TypeError(callback + " is not a function");  

                }  

                if (thisArg) {  

                    T = thisArg;  

                }  

                k = 0;  

                while (k < len) {  

                    var kValue;  

                    if (k in O) {  

                        kValue = O[k];  

                        callback.call(T, kValue, k, O);  

                    }  

                    k++;  

                }  

            };  

        } 

 

 keyArray.forEach(function(x){

                                $("#workerList").append("<option value=\""+x+"\">"+x+"</option>");

                            })

$("#workerList").combobox(

                    {

                        editable:false,    
panelHeight:'auto', onSelect:function(param){ selectChange(param) } });

 

你可能感兴趣的:(combobox)