suggest: function(){
var op = {suggest$:"#suggest", suggestShadow$: "#suggestShadow"};
var selectedIndex = -1;
return this.each(function(){
var $input = $(this).attr('autocomplete', 'off').keydown(function(event){
if (event.keyCode == DWZ.keyCode.ENTER) return false; //屏蔽回车提交
});
var suggestFields=$input.attr('suggestFields').split(",");
function _show(event){
var offset = $input.offset();
var iTop = offset.top+this.offsetHeight;
var $suggest = $(op.suggest$);
if ($suggest.size() == 0) $suggest = $('<div id="suggest"></div>').appendTo($('body'));
$suggest.css({
left:offset.left+'px',
top:iTop+'px'
}).show();
_lookup = $.extend(_lookup, {
currentGroup: $input.attr("lookupGroup") || "",
suffix: $input.attr("suffix") || "",
$target: $input,
pk: $input.attr("lookupPk") || "id"
});
var url = unescape($input.attr("suggestUrl")).replaceTmById($(event.target).parents(".unitBox:first"));
if (!url.isFinishedTm()) {
alertMsg.error($input.attr("warn") || DWZ.msg("alertSelectMsg"));
return false;
}
var postData = {};
postData[$input.attr("postField")||"inputValue"] = $input.val();
$.ajax({
type:'POST', dataType:"json", url:url, cache: false,
data: postData,
success: function(response){
if (!response) return;
var html = '';
$.each(response, function(i){
var liAttr = '', liLabel = '';
for (var i=0; i<suggestFields.length; i++){
var str = this[suggestFields[i]];
if (str) {
if (liLabel) liLabel += '-';
liLabel += str;
if (liAttr) liAttr += ',';
liAttr += suggestFields[i]+":'"+str+"'";
}
}
html += '<li lookupId="'+this[_lookup.pk]+'" lookupAttrs="'+liAttr+'">' + liLabel + '</li>';
});
var $lis = $suggest.html('<ul>'+html+'</ul>').find("li");
$lis.hoverClass("selected").click(function(){
_select($(this));
});
if ($lis.size() == 1 && event.keyCode != DWZ.keyCode.BACKSPACE) {
_select($lis.eq(0));
} else if ($lis.size() == 0){
var jsonStr = "";
for (var i=0; i<suggestFields.length; i++){
if (_util.lookupField(suggestFields[i]) == event.target.name) {
break;
}
if (jsonStr) jsonStr += ',';
jsonStr += suggestFields[i]+":''";
}
jsonStr = "{"+_lookup.pk+":''," + jsonStr +"}";
$.bringBackSuggest(DWZ.jsonEval(jsonStr));
}
},
error: function(){
$suggest.html('');
}
});
$(document).bind("click", _close);
return false;
}