Easyui's combobox realizes multiple selection and handwriting at the same time, as well as the clipboard to copy datagrid table data

html code:

The object.indexs passed in in the background is an array. After JS accepts it, it is a string, so when assigning it to combobox, it needs to be manually divided into arrays:

<s:select name="object.indexs" list="indexKeywordList" theme="simple" cssClass="__combobox"
     data-options="panelHeight:200" cssStyle="width:300px" multiple="true"/>
<input type="hidden" value="<s:property value="object.indexs"/>" id="myIndexWord"/>

JS code:

var val = $('#myIndexWord').val();
$('.__combobox').combobox({
	onHidePanel:function(){
		var inputVal = $(this).next('span').children("input:eq(0)")[0].value;//下拉框的input框中显示值
		if(inputVal){
			var arr = inputVal.split(",");
			var newArr = new Array();
			for(var i = 0;i<arr.length;i++){
				if(arr[i].indexOf("[") != -1){
                    //下拉框的面板中的值的构成为:key-key[text],例如为:1-1[选项1],表示key为1,text为1[选项1]
				    arr[i] = arr[i].substring(0,arr[i].indexOf("["));//所以这里需要把"[]"去除,保存的时候设置的值为"[]"前面的值即可
				}
				newArr.push(arr[i].replace(/\s/g, ""));//去除空白字符
			}
		}
		$(this).combobox('setValues',newArr);//设置下拉框的values
		$(this).combobox('setText',inputVal);

    },
	onLoadSuccess:function(){
        //后台传入的数组在这里接受之后,已经是这种格式:[aaa,bbb],所以赋值的时候先要去除"[]"
		if(val){
			val = val.replace("[","").replace("]","");
			var valArray = val.split(",");
			var array = [];
			for(var i = 0;i<valArray.length;i++){
				array[i] = valArray[i];
			}
			$(this).combobox("setValues",array);
		}
	}
});

E.g:

Attach a piece of code from the right-click menu of easyui's datagrid in the project to "copy formula" to the clipboard:

if(rowData.opinion){
	if(window.clipboardData){  
		//IE  
		window.clipboardData.setData("text" , rowData.opinion);  
	}else{  
		function handler(event) {
			event.clipboardData.setData('text', rowData.opinion);
			document.removeEventListener('copy', handler, true);
			event.preventDefault();
	    }
		document.addEventListener('copy', handler, true);
		document.execCommand('copy');
	}
	$.easyui.messager.show({ icon: "info", msg: "剪切板复制算式成功!", position: "topCenter" ,timeout:3000});
}

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325595420&siteId=291194637