Arrays 替换de对象ANGULARJS的属性
我有一个对象和数组,我想从中获得一个新对象,以下面的方式显示 组(阵列) 这是te服务的数组和getArrays 替换de对象ANGULARJS的属性,arrays,json,angularjs,object,Arrays,Json,Angularjs,Object,我有一个对象和数组,我想从中获得一个新对象,以下面的方式显示 组(阵列) 这是te服务的数组和get [ { "IdQuestion": "5de12577fcfabc3c50660d36", "idSurvey": "5de12546fcfabc3c50660d35", "titleQuestion": "Porque compró el producto?", "IdQuestionOption": "5de125b7fcfabc3c50660d39",
[
{
"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模型的“选择收音机”按钮生成
{
"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"
}
解决方案1
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"]
解决方案2
let res={
"5de125a8fcfabc3c50660d38": "5de12601fcfabc3c50660d42",
"5de12585fcfabc3c50660d37": "5de125f0fcfabc3c50660d3f",
"5de12577fcfabc3c50660d36": "5de125c1fcfabc3c50660d3b",
"Age": "5",
"Gender": "1",
"IdSurvey": "5de12546fcfabc3c50660d35"
}
let changed={
"Q03": res["5de125a8fcfabc3c50660d38"],
"Q02": res["5de12585fcfabc3c50660d37"],
"Q01": "res["5de12577fcfabc3c50660d36"],
"Age": res.Age,
"Gender": res.Gender,
"IdSurvey": res.IdSurvey
}