route.jsファイルを作成しました。 queryStringに基づいて、Jsonオブジェクトをフィルタリングする必要があります。 _.filterメソッドを使用すると、オブジェクト全体が応答として返されます。実際に私はここでは、コード..lodash - 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
}
がある
...事前に感謝..私を助けてくださいことproductlistノードをフィルタリングしたいと回答 として残りのノードが含まれます
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