带有json文件和嵌套数组Angularjs的http post
http post with json file and nested array Angularjs
我有一个应用程序,它能够通过关系数据库模型通过http获取和发布。我能够显示我的数据,JSON 数据在 http://localhost/**/api/complaint 上如下所示:
{
"CHECKLISTs": [{
"COMP_ID": 1,
"IntOIMRec": "No"
}],
"COMP_ID": 1,
"FileNum": "case1"
}
使用角度:
<tr data-ng-repeat="complaint in complaints">
<td><strong data-ng-hide="complaint.editMode">{{ complaint.FileNum }}</strong></td>
<td>
<p data-ng-hide="complaint.editMode">{{ complaint.CHECKLISTs[0].IntIAB}}</p>
<input data-ng-show="complaint.editMode" type="text" data-ng-model="customer.Status" />
</tr>
我还可以使用此控制器进行http发布:
//Insert complaint
$scope.add = function () {
$scope.loading = true;
$http.post('/api/Complaint/', this.newcomplaint).success(function (data) {
alert("Added Successfully!!");
$scope.addMode = false;
$scope.complaints.push(data);
$scope.loading = false;
}).error(function (data) {
$scope.error = "An Error has occured while Adding complaint! " + data;
$scope.loading = false;
});
};
但是当我将清单[0]添加到我的表单中添加它时,它不会添加新记录。我用于添加新记录的表单代码如下所示:
<div class="row">
<div class="col-md-12">
<strong class="error">{{ error }}</strong>
<p data-ng-hide="addMode"><a data-ng-click="toggleAdd()" href="javascript:;" class="btn btn-primary">Add New</a></p>
<form name="addComplant" data-ng-show="addMode" style="width:600px;margin:0px auto;">
<div class="form-group">
<label for="cid" class="col-sm-2 control-label">ID:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="cid" placeholder="please enter id" data-ng-model="newcomplaint.FileNum" required />
</div>
</div>
<div class="form-group">
<label for="cname" class="col-sm-2 control-label">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="cname" placeholder="please enter your name" data-ng-model="newcomplaint.CHECKLISTs[0].IntIAB" />
</div>
</div>
<br />
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" value="Add" data-ng-click="add()" class="btn btn-primary" />
<input type="button" value="Cancel" data-ng-click="toggleAdd()" class="btn btn-primary" />
</div>
</div>
<br />
</form>
</div>
</div>
我的控制台.log输出:
控制台.log
有人可以告诉我,如果我可以使用角度 http.get 和 http.post 来显示它,为什么当它清楚地在 JSON 文件中并且显示正常时,我不能添加到清单字段中?我得到的错误是 [对象对象] ?
谢谢
仅通过查看您的代码,您似乎正在推送$scope.complaints,而不是$scope.complaint.CHECKLISTSs
你在某处有ng重复吗?
将$scope.complaints.push(data);
更改为$scope.newcomplaint = data
。或者,如果投诉真的应该是一个数组,那么您需要在表单上ng-repeat
相关文章:
- 我无法使用angularJs($http)访问服务器
- Typescript angularjs$http获取响应类型(避免使用<any>)
- Angularjs http.get() Cross-Origin 请求被阻止
- AngularJS$http重定向状态代码
- AngularJS$http.post调用返回502(坏网关)错误
- AngularJS$http.post没有'不适用于Chrome,仅适用于IE
- angularJS $http.get communicating with API
- 如果需要登录,Angularjs$http拦截器会暂停异步请求
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- AngularJS$http返回200正常,但失败了
- AngularJS HTTP Get 没有得到响应
- Angularjs$http删除$q promise导致TypeError:对象不是函数
- Angularjs http get from ASP.NET
- AngularJS$http服务中的encodeURIComponent
- 使用AngularJS$http.get在滚动时重复请求JSON数组
- AngularJS http.jsonp请求.then和.success函数不起作用
- 由于浏览历史设置,angularjs http.get调用未在ie10中启动
- 工厂中的AngularJS$http请求
- 无法使用angularjs$http请求将参数发送到服务器操作方法
- 如何通过AngularJS$http从ASP.Net Web API 2获取访问令牌