我有一个对象和数组,我想从中获取一个新对象,以下面的方式显示。.
组(阵列)
这是te服务的数组和获取。
[
{
"IdQuestion": "5de12577fcfabc3c50660d36",
"idSurvey": "5de12546fcfabc3c50660d35",
"titleQuestion": "Porque compró el producto?",
"IdQuestionOption": "5de125b7fcfabc3c50660d39",
"idSurveyQuestion": "5de12577fcfabc3c50660d36",
"option": "Sabor"
},
{
"IdQuestion": "5de12585fcfabc3c50660d37",
"idSurvey": "5de12546fcfabc3c50660d35",
"titleQuestion": "Cómo se entero del producto?",
"IdQuestionOption": "5de125cbfcfabc3c50660d3c",
"idSurveyQuestion": "5de12585fcfabc3c50660d37",
"option": "Periodico"
},
{
"IdQuestion": "5de125a8fcfabc3c50660d38",
"idSurvey": "5de12546fcfabc3c50660d35",
"titleQuestion": "Con cuanta periodicidad consume el producto",
"IdQuestionOption": "5de125f8fcfabc3c50660d40",
"idSurveyQuestion": "5de125a8fcfabc3c50660d38", //the property is here.
"option": "Diario"
}
]
结果(对象)
这是对象,我通过ng-models的单选按钮生成
{
"5de125a8fcfabc3c50660d38": "5de12601fcfabc3c50660d42", //the property is up.
"5de12585fcfabc3c50660d37": "5de125f0fcfabc3c50660d3f",
"5de12577fcfabc3c50660d36": "5de125c1fcfabc3c50660d3b",
"Age": "5",
"Gender": "1",
"IdSurvey": "5de12546fcfabc3c50660d35"
}
我需要创建一个对象
我需要创建此对象以导出到服务
{
"Q03": "5de12601fcfabc3c50660d42",
"Q02": "5de125f0fcfabc3c50660d3f",
"Q01": "5de125c1fcfabc3c50660d3b",
"Age": "5",
"Gender": "1",
"IdSurvey": "5de12546fcfabc3c50660d35"
}
答案 0 :(得分:0)
解决方案1
export const myApiCall = (args1, arg2) => async (dispatch, getState) => {
const payload = fetch({ ...config });
return dispatch({ type: 'MY_API_CALL', payload });
}
解决方案2
let res={
"5de125a8fcfabc3c50660d38": "5de12601fcfabc3c50660d42", //the property is up.
"5de12585fcfabc3c50660d37": "5de125f0fcfabc3c50660d3f",
"5de12577fcfabc3c50660d36": "5de125c1fcfabc3c50660d3b",
"Age": "5",
"Gender": "1",
"IdSurvey": "5de12546fcfabc3c50660d35"
}
res["Q03"] = res["5de125a8fcfabc3c50660d38"]
delete res["5de125a8fcfabc3c50660d38"]
res["Q02"] = res["5de12585fcfabc3c50660d37"]
delete res["5de12585fcfabc3c50660d37"]
res["Q01"] = res["5de12577fcfabc3c50660d36"]
delete res["5de12577fcfabc3c50660d36"]