jquery autoComplete的使用代码一则

$(function() {
		$("#vipCustomer").autocomplete({
			source : function(request, response) {
				$.ajax({
					type : "post",
					url : "${basePath}AutoComplete.htm",
					dataType : "json",
					data : {
						text_search : request.term
					},
					success : function(data) {
						if (data.rows.length == 0) {
							autoCompleteSuccess = false;
							var result = [ {
								label : "无与\"" + request.term + "\"匹配的客户信息,请新建客户信息",
								value : "NoMatch"
							} ];
							response($.map(result, function(item) {
								return {
									label : item.label,
									value : '',
									id : item.value
								}
							}));
						} else {
							autoCompleteSuccess = true;
							response($.map(data.rows, function(item) {
								return {
									label : item.name,
									value : item.name,
									id : item.id,
									serialNumber : item.serialNumber
								}
							}));
						}
					}
				});
			},
			minLength : 1,
			select : function(event, ui) {
				if (ui.item.id == 'NoMatch') {
					toAddVipCustomerInfo();
				} else {
					createTable(ui.item);
				}
			},
			open : function() {
				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
			},
			close : function() {
				$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
			}
		});
	});

  

posted @ 2014-02-21 13:20  剑握在手  阅读(498)  评论(0编辑  收藏  举报
返回顶部↑