select2如何触发下拉事件?

<select class="select2" id="customer" style="width:78%;" onscroll="customerScroll()">
    var pageSize = 50;
    var customerLoadOrNo = true;
    $.post("customer/ownerCustomer", null, function(rst) {
        if (rst.customers) {
            customerList = rst.customers;
            $(function(){
                    //初始化加载一定数量的选项
                    for(var i=0;i<pageSize;i++){
                        if(customerList[i]){
                            var key = customerList[i].id + "," + HandleSpaceToZero(customerList[i].mileage) + "," + HandleSpaceToStr(customerList[i].brand) + " "
                                    + HandleSpaceToStr(customerList[i].model);
                            var value = customerList[i].customerName + "," + customerList[i].plateNo + ","
                                    +  HandleSpaceToStr(customerList[i].mobile) + "," +  HandleSpaceToStr(customerList[i].cardNo);
                            optionStr += "<option value='" + key + "'>" + value
                                    + "</option>";
                        }else{
                            break;
                        }
                    }
                    $("#customer").append(optionStr);
            });
            
                return initSelect(rst.customers);
        }
    }, "json");
    
    function customerScroll(){       
                    var vst = parseInt($('#customer')[0].scrollTop);
                    var vsh =  parseInt($('#customer')[0].scrollHeight);
                    var vch =  parseInt($('#customer')[0].clientHeight);
                    var len =  $('#customer option').length;
                    //如果下拉到底,判断是否要继续加载
                    if((vst + vch == vsh) && loadOrNo){
                            //这里可以异步取数据,根据返回结果判断是否继续加载
                            if(len > rst.customers.length()){
                                    customerLoadOrNo = false;
                                }
                            for(var i=len+1;i<len+pageSize;i++){
                                if(rst.customers[i]){
                                    var key = customer.id + "," + HandleSpaceToZero(customer.mileage) + "," + HandleSpaceToStr(customer.brand) + " "
                                            + HandleSpaceToStr(customer.model);
                                    var value = customer.customerName + "," + customer.plateNo + ","
                                            +  HandleSpaceToStr(customer.mobile) + "," +  HandleSpaceToStr(customer.cardNo);
                                    optionStr += "<option value='" + key + "'>" + value
                                            + "</option>";
                                }else{
                                    break;
                                }
                            }
                            $("#customer").append(optionStr);
                    }
    }

现在的问题是无法触发customerScroll()方法,该怎么解决,求大神们指导!

感恩!

空麻袋背米
浏览 7407回答 1
1回答

Suber丶林

select标签,用的是change事件。
打开App,查看更多内容
随时随地看视频慕课网APP