我想从nodejs获取数组数据。特别是我很期待获得使用Jquery检索数据但无法的每个结果的文件名。我不知道该怎么做。
router.post('/womensearch',(req,res)=>{
const searchItem = req.body.womenitem;
// If it is Catagory
gfs.collection('wdress').find({
$and:[{ $or : [{'metadata.cat': searchItem},{'metadata.brand':
searchItem}]}]
}).toArray((err,files)=>{
res.end(JSON.stringify(files)); <- Here is my problem
});
});
这是Jquery代码
function womenSearch(){
$(document).ready(function(){
const search_item = $('#womenItem').val();
$.ajax({
method:'POST',
url:'/womensearch',
cache:false,
data:{
womenitem:search_item
},
success:function(data){
},
error:function(){
}
});
});
}
</script>
这是我从数据库中获得的结果。
{ _id: 5c62dfbf87dda7249c87c190,
length: 129450,
chunkSize: 261120,
uploadDate: 2019-02-12T15:01:19.617Z,
filename: 'd03e3359c03a5d885e85d6a48c6424a5.jpg',
md5: '88f70c2f16f1367fe7198775a3912daa',
contentType: 'image/jpeg',
metadata:
{ brand: 'Mango',
cat: 'Coats',
name: 'Harish',
color: 'Blue',
price: '2750',
info: 'Stylish gesture for women ',
dis: '50',
Likes: 2 } },
{ _id: 5c62e3d20a7a574dbc7c0044,
length: 150261,
chunkSize: 261120,
uploadDate: 2019-02-12T15:18:42.036Z,
filename: 'eb1528f1e7e9707f2d79a6d97981a9c8.jpg',
md5: '08c1bcd73521e00f6b4857363f950e52',
contentType: 'image/jpeg',
metadata:
{ brand: 'Mango',
cat: 'Coats',
name: 'Harish',
color: 'Blue',
price: '5000',
info: 'This is wonderful ',
dis: '0',
Likes: 0 } } ]
通过Jquery回调函数发送数据的任何提示。
答案 0 :(得分:0)
您需要先将结果解析为json
,然后才能访问它。
resultJSON = JSON.parse(data);