layui下拉框js封裝
阿新 • • 發佈:2018-11-24
/** * 初始化返回資料型別下拉框 * @param comboboxId 下拉框ID * @param param 自定義sql要傳入的引數,例如 {cfgCode:'ENUM_GETTER',enumCategoryId:enumCategoryId} 其中cfgCode為必傳引數 * @param needAll true:代表顯示全部 * @param onSelectValue 預設需要選中的值,否則預設選中第一個 */ function initSelect(comboboxId,param,needAll,onSelectValue){ var url = path + "/app/signal/common/commonDataQuery!getDataByCfgCodeJustData.action"; $.ajax( { type : 'post', url : url, data : param, async : true, success : function(data) { var arr = needAll === true ? [{"id":"","value":"","text":"全部"}] : []; arr=arr.concat($.parseJSON(data)); var $html = ""; for(var i=0;i<arr.length;i++){ if(onSelectValue && arr[i].value==onSelectValue){ $html += "<option value='" + arr[i].value + "' selected>" + arr[i].text + "</option>"; }else{ $html += "<option value='" + arr[i].value + "'>" + arr[i].text + "</option>"; } } $("#"+comboboxId).append($html); } }); }