我有以下JSON数据Feed:
jQuery191029421305245357143_1380819227858(
{
"responseHeader": {
"status": 0,
"QTime": 127
},
"command": "build",
"spellcheck": {
"suggestions": [
"restaurant",
{
"numFound": 1,
"startOffset": 0,
"endOffset": 10,
"suggestion": [
"restaurants"
]
},
"berl",
{
"numFound": 4,
"startOffset": 11,
"endOffset": 15,
"suggestion": [
"berlin",
"berlin brandenburg",
"berlin hamburg",
"berliner"
]
},
"collation",
"restaurant berlin",
"collation",
"restaurant (berlin brandenburg)",
"collation",
"restaurants berlin",
"collation",
"restaurant (berlin hamburg)"
]
}
}
)
我尝试在JQuery中访问以下数据:
"restaurant berlin"
"restaurant (berlin brandenburg)"
"restaurants berlin"
"restaurant (berlin hamburg)"
到目前为止,我有以下JQUERY代码:
success: function( data ) {
response( $.map(data.spellcheck.suggestions, function(item) {
return item;
}));
哪个有效,但返回所有值,而不仅仅是上面列出的4个数据集。
感谢您的帮助!
答案 0 :(得分:0)
在jQuery map
- 函数的回调中,如果你不想在结果中使用该项,你可以进行检查并返回null。
以下代码段显示了如何过滤掉不是字符串的所有内容以及字符串等于“排序规则”的所有内容的示例:
success: function( data ) {
response( $.map(data.spellcheck.suggestions, function(item) {
if (typeof item != "string") return;
if (item === "collation") return;
return item;
}));