(function( $ ) { $.widget( "ui.combobox", { options: { editable: false, ajax: false,// 是否异步请求数据 datatablelogicid: "",// 表id childtarget: "",// 子checkbox控件 textcolumn: "",// 显示列 autoload : true, // 自动加载 valuecolumn: "",// 存储列 type: "",// 类型(singleselect:单级下拉列表,multiselect:多级下拉列表) property: {},// 查询条件应为{key:value}格式的字符串 id: "",// input 的id button: true, onselect: function(){},// 选中事件 afteraddoptions: function(){}// 添加options后事件 }, _create: function() { var input, that = this, select = this.element.hide(), wrapper = this.wrapper = $( "
" + item.label + "" ) .appendto( ul ); }; if(that.options.button){ input.css({ width: "90%", "line-height": input.height() + "px" }); $( "" ) .attr( "tabindex", -1 ) .attr( "title", "显示所有" ) .css("height", select.height()) .appendto( wrapper ) .button({ icons: { primary: "ui-icon-triangle-1-s" }, text: false }) .removeclass( "ui-corner-all" ) .addclass( "ui-corner-right ui-combobox-toggle" ) .click(function() { // close if already visible if ( input.autocomplete( "widget" ).is( ":visible" ) ) { input.autocomplete( "close" ); removeifinvalid( input ); return; } // work around a bug (likely same cause as #5265) $( this ).blur(); // pass empty string as value to search for, displaying all results input.autocomplete( "search", "" ); input.focus(); }); }else{ input.css({ width: "100%", "line-height": input.height() + "px" }); } this.element.data("input", input); }, setval: function(value) { this.element.val(value); var input = this.element.data("input"); input.val(this.element.children(":selected").text()); }, refresh: function(data) { // 刷新 var select = this.element; // 判断是否异步请求 if(this.options.ajax){ $(select).empty(); // 文本框 var input = this.element.data("input"); input.val(""); addoptions(select, this, {selectpid: data.id}); } }, destroy: function() { this.wrapper.remove(); this.element.show(); $.widget.prototype.destroy.call( this ); } }); // 在异步请求的情况下使用ajax添加option function addoptions(element, that, property){ // 添加一个空的option $("") .appendto(element); $.ajax({ url: contextrootpath + "/release/searchoptionsajax.xhtml", type: "post", datatype: "json", async:false, data: { "datatablelogicid": that.options.datatablelogicid, "property": json.stringify($.extend(that.options.property, property)), "formlogicid": that.options.formlogicid, "type": that.options.type, "infopathlogicid": that.options.infopathlogicid }, success: function(datas){ if(datas.error){ alert(datas.msg); return; } $.each(datas, function(k, data){ $("") .data("bindeddata",data) .appendto(element); }); element.val(that.element.attr("defaultvalue")); that.options.afteraddoptions.call(that.element, datas); } }); } })( jquery );