Javascript 我们如何搜索并找到与“搜索文本”匹配的属性名称“schools”的“Array number”`
我们如何在复杂的Json数组中搜索并找到属性名Javascript 我们如何搜索并找到与“搜索文本”匹配的属性名称“schools”的“Array number”`,javascript,Javascript,我们如何在复杂的Json数组中搜索并找到属性名学校的数组编号,与一些搜索文本匹配,如下所示:我尝试了下面的代码,但它不起作用 const searchText = "South School"; var myArr = []; myArr = response.body.schools; var results = myArr.filter(function(myArr) { return myArr.schools.indexOf(searchText) > -1; });
学校的数组编号
,与一些搜索文本
匹配,如下所示:我尝试了下面的代码,但它不起作用
const searchText = "South School";
var myArr = [];
myArr = response.body.schools;
var results = myArr.filter(function(myArr) {
return myArr.schools.indexOf(searchText) > -1;
});
基于上面的搜索文本,我需要从下面的json中找到与搜索文本匹配的数组号。当我观察chrome控制台时,我可以看到以下阵列范围
试试这个
var results=myArr.filter(函数(myarlement)){
返回myarElement.schools.name.indexOf(searchText)>-1;
});代码>根据示例数据,您需要过滤三次
var searchText=“南方学校”;
var学校=[];
var arr=[
{
“最新更新”:“2019-08-27T00:07:58.7222559+00:00”,
“警报”:[
{
“id”:“ea229500-bc49-4dda”,
“学校”:[
{
“id”:“b04fc2fb-3e62-4b4e”,
“姓名”:“北方学校上层”,
“区域”:“北岛”,
“车站”:“125001”,
“最新更新”:“2019-08-27T00:00:11.7304497+00:00”,
“percentageFull”:0.00,
“winStorageUrl”:https://testurl.com"
}
],
“最新更新”:“2019-08-25T03:47:26.0493451+00:00”,
“头衔”:“北方学校”,
“副标题”:“预测结果”,
“描述”:“北方学校”,
“地位”:1,
“状态描述”:“草稿”,
“日程安排”:“2019-08-28T03:30:00+00:00”,
“deletedDate”:空,
“isInApp”:错,
“isEmailNotification”:错误,
“facebookPost”:空,
“twitterPost”:“学校的第一篇twitterPost”
},
{
“id”:“a4d78fdf-bcca-4304”,
“学校”:[
{
“id”:“e8b45981-53aa-4061”,
“名称”:“南方学校”,
“地区”:“远南学校”,
“车站”:“110A”,
“最新更新”:“2019-08-27T00:00:11.7305428+00:00”,
“percentageFull”:0.00,
“winStorageUrl”:http://testurl"
}
],
“最新更新”:“2019-08-27T00:01:33.4345038+00:00”,
“标题”:“一些新想法”,
“副标题”:“蓝莓看到橘子。”,
“描述”:“不幸的是,这是错误的;相反,一些熟练的蛇”,
“地位”:3,
“状态描述”:“已发送”,
“imageUrl”:空,
“scheduledFor”:空,
“deletedDate”:空,
“isInApp”:没错,
“isEmailNotification”:正确,
“facebookPost”:“更新时插入Facebook帖子\n”,
“twitterPost”:“创建时插入了twitterPost\n”
}
]
},
{
“最新更新”:“2019-08-27T00:07:58.7222559+00:00”,
“警报”:[
{
“id”:“ea229500-bc49-4dda”,
“学校”:[
{
“id”:“b04fc2fb-3e62-4b4e”,
“姓名”:“北方学校上层”,
“区域”:“北岛”,
“车站”:“125001”,
“最新更新”:“2019-08-27T00:00:11.7304497+00:00”,
“percentageFull”:0.00,
“winStorageUrl”:https://testurl.com"
}
],
“最新更新”:“2019-08-25T03:47:26.0493451+00:00”,
“头衔”:“北方学校”,
“副标题”:“预测结果”,
“描述”:“北方学校”,
“地位”:1,
“状态描述”:“草稿”,
“日程安排”:“2019-08-28T03:30:00+00:00”,
“deletedDate”:空,
“isInApp”:错,
“isEmailNotification”:错误,
“facebookPost”:空,
“twitterPost”:“学校的第一篇twitterPost”
},
{
“id”:“a4d78fdf-bcca-4304”,
“学校”:[
{
“id”:“e8b45981-53aa-4061”,
“名称”:“南方学校”,
“地区”:“远南学校”,
“车站”:“110A”,
“最新更新”:“2019-08-27T00:00:11.7305428+00:00”,
“percentageFull”:0.00,
“winStorageUrl”:http://testurl"
}
],
“最新更新”:“2019-08-27T00:01:33.4345038+00:00”,
“标题”:“一些新想法”,
“副标题”:“蓝莓看到橘子。”,
“描述”:“不幸的是,这是错误的;相反,一些熟练的蛇”,
“地位”:3,
“状态描述”:“已发送”,
“imageUrl”:空,
“scheduledFor”:空,
“deletedDate”:空,
“isInApp”:没错,
“isEmailNotification”:正确,
“facebookPost”:“更新时插入Facebook帖子\n”,
“twitterPost”:“创建时插入了twitterPost\n”
}
]
},
{
“最新更新”:“2019-08-27T00:07:58.7222559+00:00”,
“警报”:[
{
“id”:“ea229500-bc49-4dda”,
“学校”:[
{
“id”:“b04fc2fb-3e62-4b4e”,
“姓名”:“北方学校上层”,
“区域”:“北岛”,
“车站”:“125001”,
“最新更新”:“2019-08-27T00:00:11.7304497+00:00”,
“percentageFull”:0.00,
“winStorageUrl”:https://testurl.com"
}
],
“最新更新”:“2019-08-25T03:47:26.0493451+00:00”,
“头衔”:“北方学校”,
“副标题”:“预测结果”,
“描述”:“北方学校”,
“地位”:1,
“状态描述”:“草稿”,
“日程安排”:“2019-08-28T03:30:00+00:00”,
“deletedDate”:空,
“isInApp”:错,
“isEmailNotification”:错误,
“facebookPost”:空,
“twitterPost”:“学校的第一篇twitterPost”
},
{
“id”:“a4d78fdf-bcca-4304”,
“学校”:[
{
“id”:“e8b45981-53aa-4061”,
“名称”:“南方学校”,
“瑞吉
{
"lastUpdated":"2019-08-27T00:07:58.7222559+00:00",
"alerts":[
{
"id":"ea229500-bc49-4dda",
"schools":[
{
"id":"b04fc2fb-3e62-4b4e",
"name":"North School-Upper",
"region":"North Island",
"station":"125001",
"lastUpdate":"2019-08-27T00:00:11.7304497+00:00",
"percentageFull":0.00,
"winStorageUrl":"https://testurl.com"
}
],
"lastUpdate":"2019-08-25T03:47:26.0493451+00:00",
"title":"North School",
"subTitle":"Forecast results",
"description":"North School",
"status":1,
"statusDescription":"Draft",
"scheduledFor":"2019-08-28T03:30:00+00:00",
"deletedDate":null,
"isInApp":false,
"isEmailNotification":false,
"facebookPost":null,
"twitterPost":"First twitter post of school"
},
{
"id":"a4d78fdf-bcca-4304",
"schools":[
{
"id":"e8b45981-53aa-4061",
"name":"South School",
"region":"Far South School",
"station":"110A",
"lastUpdate":"2019-08-27T00:00:11.7305428+00:00",
"percentageFull":0.00,
"winStorageUrl":"http://testurl
}
],
"lastUpdate":"2019-08-27T00:01:33.4345038+00:00",
"title":"Some new ideas",
"subTitle":"A blueberry sees an orange.",
"description":"Unfortunately, that is wrong; on the contrary, some skillful snakes",
"status":3,
"statusDescription":"Sent",
"imageUrl":null,
"scheduledFor":null,
"deletedDate":null,
"isInApp":true,
"isEmailNotification":true,
"facebookPost":"Facebook post inserted while updating\n",
"twitterPost":"Twitter post inserted while creating\n"
},....
// JSOn data continues here
]
}