日期:2014-05-16  浏览次数:20641 次

新手请教传递参数问题
var dropdown = function (stringUrl) {
this.stringKeySpliter = "";
this.stringRecordSpliter = "|";
this.stringSystemKeys = "s,sh,sz,0,1,2,3,4,5,6,7,8,9";
this.arraySystemKeys = new Array();
this.arrayPrepareKeys = new Array();
this.intPrepareKeysMaxLength = 50;
this.stringData = new String();
this.getNearestData = function (stringKey) {
if (this.arrayPrepareKeys.length == 0) {
return new String();
}
var arrayContainers = new Array();
for (var i =0; i < this.arraySystemKeys.length; i++) {
if (this.arraySystemKeys[i][0] == stringKey) {
return this.arraySystemKeys[i][1];
}
if (stringKey.match(new RegExp("^" + this.arraySystemKeys[i][0], "igm")) != null) {
arrayContainers.push(this.arraySystemKeys[i]);
}
}
for (var i = 0; i < this.arrayPrepareKeys.length; i++) {
if (this.arrayPrepareKeys[i][0] == stringKey) {
return this.arrayPrepareKeys[i][1];
}
if (stringKey.match(new RegExp("^" + this.arrayPrepareKeys[i][0], "igm")) != null) {
arrayContainers.push(this.arrayPrepareKeys[i]);
}
}
if (arrayContainers.length == 0) {
return new String();
}
else {
arrayContainers.sort(
function (arrayA, arrayB) {
return arrayB[0].length - arrayA[0].length;
}
);
return arrayContainers[0][1];
}
};


this.getResult = function (stringData, stringKey) {
var stringRegExpSystem = "$()*+.[?\^{|";
var stringKeySpliter = (stringRegExpSystem.indexOf(this.stringKeySpliter) < 0 ? "" : "\\") + this.stringKeySpliter;
var stringRecordSpliter = (stringRegExpSystem.indexOf(this.stringRecordSpliter) < 0 ? "" : "\\") + this.stringRecordSpliter;
var arrayMatchResult = stringData.match(new RegExp("" + stringRecordSpliter + (isNaN(parseInt(stringKey)) ? "" : "(s[hz])?") + stringKey + "[^\\" + stringRecordSpliter + "|" + stringKeySpliter + "]*" + stringKeySpliter + "[^\\" + stringRecordSpliter + "|" + stringKeySpliter + "|\n]*", "igm"));
return arrayMatchResult == null ? new Array() : arrayMatchResult;
};


this.getQuickResult = function (stringKey) {
stringKey = stringKey.split(this.stringKeySpliter).join("").split(this.stringRecordSpliter).join("");
if (stringKey == "") {
return new Array();
}
var stringNearestData = this.getNearestData(stringKey);
var arrayResult = stringNearestData == "" ? this.getResult(this.stringData, stringKey) : this.getResult(stringNearestData, stringKey);
arrayResult = arrayResult == null ? new Array() : arrayResult;
var booleanIsInSystemKeys = false;
for (var i = 0; i < this.arraySystemKeys.length; i++) {
if (this.arraySystemKeys[i][0] == stringKey) {
booleanIsInSystemKeys = true;
break;
}
}
var booleanIsInPrepareKeys = false;
for (var i = 0; i < this.arrayPrepareKeys.length; i++) {
if (this.arrayPrepareKeys[i][0] == stringKey) {
booleanIsInPrepareKeys = true;
break;
}
}
if (!booleanIsInSystemKeys && !booleanIsInPrepareKeys) {
this.arrayPrepareKeys.push(new Array(stringKey, arrayResult.join("")));
if (this.arrayPrepareKeys.length > this.intPrepareKeysMaxLength) {
this.arrayPrepareKeys.sort(
function (arrayA, arrayB) {
return arrayA[0].length - arrayB[0].length;
}
);
this.arrayPrepareKeys.pop();
}
}
return arrayRes