【发布时间】:2015-02-17 06:05:08
【问题描述】:
我正在创建一个采用这样的 JSON 的 API:
"hightlights":[
{
"title":"Fun",
"url":"fun/index.html",
"queries":
[
"music",
"artists",
"events",
"internet"
]
},
{
"title":"Internet",
"url":"internet/index.html",
"queries":
[
"javascript",
"web",
"internet",
]
}
]
我需要使用用户给出的单词过滤 JSON,然后返回另一个 JSON,其中只有包含“查询”中的单词的对象。
If word === 'music', receive:
{
"title":"Fun",
"url":"fun/index.html",
"queries":[
"music",
"artists",
"events",
"internet"
]
}
If word === 'internet', receive:
{
{
"title":"Fun",
"url":"fun/index.html",
"queries":[
"music",
"artists",
"events",
"internet"
]
},
{
"title":"Internet",
"url":"internet/index.html",
"queries":[
"javascript",
"web",
"internet",
]
}
我的问题是如何嵌套这些值?如果有人可以给我一些例子...我会很感激...
【问题讨论】:
-
“如何嵌套这个值”是什么意思?
-
如何过滤内部查询并返回所有包含这个词的对象?
-
如果我需要过滤部分字符串如“mus”,我该怎么做?
标签: javascript json api filter