【问题标题】:Replace Property of de object ANGULARJS替换对象 ANGULARJS 的属性
【发布时间】:2020-03-27 04:01:07
【问题描述】:

我有一个对象和数组,我想从中获取一个新对象以如下方式显示..

组(数组)

这是服务的数组和获取。

[
  {
    "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"
}

【问题讨论】:

    标签: arrays json angularjs object


    【解决方案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
    
           }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-07
      • 2017-09-05
      • 2018-09-29
      • 2021-11-26
      • 2020-03-23
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多