我有一个看起来像这样的Jsonresult。
[{
"comP_ID": 9,
"fileNum": "T2015",
"croRoute_DT": "2016-03-30T00:00:00",
"checklisTs": [],
"assoC_INC_OFFs": [{
"aiO_ID": 14,
"comP_ID": 9,
"ofcnum": 1,
"linK_TYPE": "Officer",
"allegatioNs": [{
"alleG_ID": 33,
"iabAllegation": "allegation1",
"disciplinedetaiLs": [{
"disciplineDetail_ID": 9,
"penalty": null
}, {
"disciplineDetail_ID": 10,
"penalty": null
}]
}, {
"alleG_ID": 59,
"iabAllegation": "allegation12",
"disciplinedetaiLs": []
}, {
"alleG_ID": 1061,
"iabAllegation": null,
"disciplinedetaiLs": []
}],
"officerinvolveDs": null
}, {
"aiO_ID": 55,
"comP_ID": 9,
"ofcnum": 1,
"linK_TYPE": "Officer",
"allegatioNs": [{
"alleG_ID": 27,
"iabAllegation": "allegation11",
"disciplinedetaiLs": []
}, {
"alleG_ID": 51,
"iabAllegation": "allegation2",
"disciplinedetaiLs": []
}, {
"alleG_ID": 1056,
"iabAllegation": "allegation3",
"disciplinedetaiLs": []
}, {
"alleG_ID": 60,
"iabAllegation": null,
"disciplinedetaiLs": []
}],
"officerinvolveDs": null
}, {
"aiO_ID": 56,
"comP_ID": 9,
"ofcnum": 2,
"linK_TYPE": "Officer",
"allegatioNs": [{
"alleG_ID": 28,
"iabAllegation": "allegation11",
"disciplinedetaiLs": []
}, {
"alleG_ID": 29,
"iabAllegation": "allegation2",
"disciplinedetaiLs": []
}],
"officerinvolveDs": null
}]
}]
我已经相应地设置了所有api,并且能够在父级别和子级别推送数据,但是当我到达子级别的孩子时,我收到了错误的请求错误。
什么有用
$scope.comps.push(data);
$scope.comp.assoC_INC_OFFs.push(data);
但是当我到达allegatioNs表时,我尝试了多种方式,它不会起作用:
$scope.comp.assoC_INC_OFFs.allegatioNs.push(data);
或
$scope.comp.assoC_INC_OFFs[0].allegatioNs.push(data);
我调用comps的函数:
getComp();
function getComp() {
Service.getComp()
.success(function (comp) {
$scope.comps = []
$scope.comps = comp;
$scope.index = 0;
$scope.comp = $scope.comps[0];
}
我要添加的功能:
$scope.updateAlleg = function (alleG_ID) {
var id = alleG_ID;
$http.post('/crams/api/aio/' + id + '/allegs', $scope.comp.assoC_INC_OFFs.allegatioNs).success(function (data) {
//console.log("updated Successfully!!");
$scope.comp.assoC_INC_OFFs.allegatioNs.push(data);
$scope.loading = false;
}).error(function (data) {
$scope.error = "An Error has occured while updated Customer! " + data;
$scope.loading = false;
alert('Did Not Save!');
console.log($scope.error);
});
};
我的错误说:
ModelState是无效的'
问题 有人可以帮我找出将数据推送到指控表的正确方法吗?
答案 0 :(得分:0)
您的$scope.comps
如何填充?
我不知道您是如何接收/解析数据的,但它在我的结束时工作正常:
var comps = JSON.parse('[{"comP_ID":9,"fileNum":"T2015","croRoute_DT":"2016-03-30T00:00:00","checklisTs":[],"assoC_INC_OFFs":[{"aiO_ID":14,"comP_ID":9,"ofcnum":1,"linK_TYPE":"Officer","allegatioNs":[{"alleG_ID":33,"iabAllegation":"allegation1","disciplinedetaiLs":[{"disciplineDetail_ID":9,"penalty":null},{"disciplineDetail_ID":10,"penalty":null}]},{"alleG_ID":59,"iabAllegation":"allegation12","disciplinedetaiLs":[]},{"alleG_ID":1061,"iabAllegation":null,"disciplinedetaiLs":[]}],"officerinvolveDs":null},{"aiO_ID":55,"comP_ID":9,"ofcnum":1,"linK_TYPE":"Officer","allegatioNs":[{"alleG_ID":27,"iabAllegation":"allegation11","disciplinedetaiLs":[]},{"alleG_ID":51,"iabAllegation":"allegation2","disciplinedetaiLs":[]},{"alleG_ID":1056,"iabAllegation":"allegation3","disciplinedetaiLs":[]},{"alleG_ID":60,"iabAllegation":null,"disciplinedetaiLs":[]}],"officerinvolveDs":null},{"aiO_ID":56,"comP_ID":9,"ofcnum":2,"linK_TYPE":"Officer","allegatioNs":[{"alleG_ID":28,"iabAllegation":"allegation11","disciplinedetaiLs":[]},{"alleG_ID":29,"iabAllegation":"allegation2","disciplinedetaiLs":[]}],"officerinvolveDs":null}]}]');
console.log('before push', comps[0].assoC_INC_OFFs);
comps[0].assoC_INC_OFFs.push({'data' : 'somedata'});
console.log('after push', comps[0].assoC_INC_OFFs);
结果:
before push [Object, Object, Object]
after push [Object, Object, Object, Object]