这是我的数据对象会是什么样子http://jsfiddle.net/303tpLtz/1嵌套分类搜索使用下划线JS
正如你可以看到here里面有分类类别所以,问题是当搜索完成
必须考虑我可以用_.findWhere(result.response.categories, {name: 'Arts & Entertainment'})
找到类别的顶级名称,但问题是,当我需要找到提供的请求中提到的某些东西,例如,如果我需要找到一个餐厅,里面食品>
任何人都可以帮助我的深度搜索功能吗?
我纠结的解决方案jsFiddle:
function findDeep(cats, attrs) {
_.each(cats, function(data, i) {
var copy = data;
// delete copy.categories;
newArr.push(copy);
_.each(data.categories, function(newObj) {
var copy2 = newObj;
// delete copy2.categories;
newArr.push(copy2)
if (newObj.categories) {
_.each(newObj.categories, function(otherObj) {
var copy3 = otherObj;
// delete copy3.categories;
newArr.push(copy3)
})
}
})
});
return _.findWhere(newArr, attrs) || null;
}
猜测:[Underscore.js - 以嵌套的Json过滤(https://stackoverflow.com/questions/22994658/underscore-js-filtering-in-a-nested-json)。互联网搜索:_'Underscore.js - 在嵌套的Json中过滤__。是更多的猜测 –
没有@RyanVincent,如果你看起来很近,请在我的类别里有更多的json对象,当搜索完成时需要考虑https://gist.github.com/sahanDissanayake/b29c913a00d33bffc67f#file-gistfile1-js- L199 – Sahan