Javascript Angularjs从Json对象中删除子对象

Javascript Angularjs从Json对象中删除子对象,javascript,angularjs,json,removechild,Javascript,Angularjs,Json,Removechild,当我试图删除子对象时,我得到了一个错误 TypeError:ctrl.otsact.tests.splice不是函数 HTML: <tr ng-repeat="act in ctrl.otsact.tests" ng-if="ctrl.editToggle"> <td><span ng-click="ctrl.removeOTSACT(act.id)"> Delete </span></td> </tr> Json

当我试图删除子对象时,我得到了一个错误

TypeError:ctrl.otsact.tests.splice不是函数

HTML:

<tr ng-repeat="act in ctrl.otsact.tests" ng-if="ctrl.editToggle">
    <td><span ng-click="ctrl.removeOTSACT(act.id)"> Delete </span></td>
</tr>
Json对象

{  
   "ACT":{  
      "name":"ACT",
      "tests":{  
         "73":{  
            "id":73,
            "official_test_id":1,
            "student_id":165888,
            "test_date":"2017-05-12",
            "score":"0.0",
            "created_at":"2017-05-23 13:50:40",
            "created_by_id":2766,
            "updated_at":"2017-05-23 13:50:40",
            "updated_by_id":2766,
            "subjects":[  
               {  
                  "id":1,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":1,
                  "score":1,
                  "student_score_id":73,
                  "name":"English",
                  "is_consider":1
               },
               {  
                  "id":2,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":2,
                  "score":1,
                  "student_score_id":73,
                  "name":"Math",
                  "is_consider":1
               },
               {  
                  "id":3,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":3,
                  "score":1,
                  "student_score_id":73,
                  "name":"Reading",
                  "is_consider":1
               },
               {  
                  "id":4,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":4,
                  "score":1,
                  "student_score_id":73,
                  "name":"Science",
                  "is_consider":1
               },
               {  
                  "id":5,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":5,
                  "score":1,
                  "student_score_id":73,
                  "name":"Writing",
                  "is_consider":0
               }
            ]
         },
         "74":{  
            "id":74,
            "official_test_id":1,
            "student_id":165888,
            "test_date":"2017-05-12",
            "score":"0.0",
            "created_at":"2017-05-23 13:50:40",
            "created_by_id":2766,
            "updated_at":"2017-05-23 13:50:40",
            "updated_by_id":2766,
            "subjects":[  
               {  
                  "id":1,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":1,
                  "score":2,
                  "student_score_id":74,
                  "name":"English",
                  "is_consider":1
               },
               {  
                  "id":2,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":2,
                  "score":2,
                  "student_score_id":74,
                  "name":"Math",
                  "is_consider":1
               },
               {  
                  "id":3,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":3,
                  "score":2,
                  "student_score_id":74,
                  "name":"Reading",
                  "is_consider":1
               },
               {  
                  "id":4,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":4,
                  "score":2,
                  "student_score_id":74,
                  "name":"Science",
                  "is_consider":1
               },
               {  
                  "id":5,
                  "official_test_id":1,
                  "student_id":165888,
                  "official_test_subject_id":5,
                  "score":2,
                  "student_score_id":74,
                  "name":"Writing",
                  "is_consider":0
               }
            ]
         }
      }
   }
}
在上面的脚本中我做错了什么


谢谢。

在JSON表示中,ctrl.otsact.ACT.tests不是数组。如果您可以更改JSON,使“tests”是一个数组,那么拼接将起作用。

这是一个对象而不是数组,因此您无法拼接它。 更改此项:

ctrl.otsact.tests.splice(index, 1);
为此:

delete ctrl.otsact.tests[index];

您可能需要在使用splice之前解析您的变量,就像您的变量是一个对象一样?
delete ctrl.otsact.tests[index];