function searchList(str, container) {
var newList = [];
//新的列表
var startChar = str.charAt(0);
//开始字符
var strLen = str.length;
//查找符串的长度
for (var i = 0; i < container.length; i++) {
var obj = container[i];
var isMatch = false;
for (var p in obj) {
if (typeof (obj[p]) == "function") {
obj[p]();
} else {
var curItem = "";
if (obj[p] != null) {
curItem = obj[p];
}
for (var j = 0; j < curItem.length; j++) {
if (curItem.charAt(j) == startChar)
{
if (curItem.substring(j).substring(0, strLen) == str)
{
isMatch = true;
break;
}
}
}
}
}
if (isMatch) {
newList.push(obj);
}
}
return newList;
}
JS 数组模糊搜索
最新推荐文章于 2024-07-08 21:41:31 发布