所以我有以下代码,它返回一个包含其他三个数组的数组,而不是仅返回一个包含对象的数组。有什么方法可以做到这一点吗?
这是返回的响应,我想只保留带有对象的主数组
Array [
Array [
Object {
"_id": "5b276afd8d05600a78e91fea",
"description": "",
"location": Array [
Object {
"_id": "5b276afd8d05600a78e91feb",
"city": "London",
},
],
"postDate": "2018-06-18T08:18:16.893Z",
"title": "Post Michael 1",
},
Object {
"_id": "5b276c35bab2220ae8ec8859",
"description": "",
"location": Array [
Object {
"_id": "5b276c35bab2220ae8ec885a",
"city": "London",
},
],
"postDate": "2018-06-18T08:18:16.893Z",
"title": "Post Michael 2",
},
],
Array [],
Array [
Object {
"_id": "5b27a44b91b02c10450fef7e",
"description": "",
"location": Array [
Object {
"_id": "5b27a44b91b02c10450fef7f",
"city": "London",
},
],
"postDate": "2018-06-18T12:23:32.508Z",
"title": "Post Sarah 1",
},
],
]
这是我的函数返回此
export function getAllJobs(dispatch, getState) {
const state = getState();
const { token } = state.auth;
return axios.get(JOBS_ALL_URL, {
headers: { authorization: token }
}).then((response) => {
var result = [];
response.data.map(o => {
result.push(o.jobs);
});
console.log(result);
dispatch(setJobs(result));
}).catch((err) => {
dispatch(console.log("Couldn't get jobs."));
});
}