【发布时间】:2019-07-09 16:36:01
【问题描述】:
我想从 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 回调函数发送数据的任何提示。
【问题讨论】:
-
当你的
logresponse成功时你会得到什么? -
如果我在成功博客中提到 data 我会得到一个 Json 文件的整个结果但是如果我提到 data.filename 我会得到未定义
-
正是我不知道如何通过成功博客获取数组结果