route.js 파일을 만들었습니다. queryString에 따라 Json 객체를 필터링해야합니다. _.filter 메서드를 사용하면 전체 객체를 응답으로 반환합니다. 사실 나는lodash - 자식을 _filter하고 json 파일에서 모든 부모를 반환하는 방법은 무엇입니까?
JSON 파일 .. 여기
코드입니다 ... .. 사전에 감사를 그 제품 목록 노드를 필터링 원하는 나를 제발 도와주세요 응답으로 나머지 노드를 포함{
"productList": [
{
"productName": "xyz",
"productType": "mobile"
},
{
"productName": "xyz",
"productType": "mobile"
},
{
"productName": "xyz",
"productType": "mobile"
}
],
"totalProducts": 3,
"FilteredProducts": 0,
"test1": 11,
"test11": 12,
"test33": 13
}
route.js
var filterByProduct = function(coll, productType){
return _.forEach(coll, function(o){
return _.find(o, function(item){
});
});
};
var queryString = function(req, res, next) {
if (req.query.productType) {
var stringObj = JSON.stringify(filterByProduct(jsonFile, req.query.productType),null,4);
res.end(stringObj);
} else if (req.query !== {}) {
var stringObj = JSON.stringify(jsonFile,null,4);
res.end(stringObj);
} else {
res.end('Not a Query String');
}
}
router.get('/test', queryString, function(req,res){
//
});
고맙습니다. 너는 나를 구해 줬어. – Learner17
다행이야. 내가 도울 수있어! – foundling