【发布时间】:2016-03-03 10:58:28
【问题描述】:
我有一张桌子。行表的每个单元格都是表单域。另外,我有两个按钮:一个按钮将新行添加到表中,第二个按钮发送所有行。
这是用于添加新的空白行:
$scope.atributs =[];
$scope.addRow = function(){
var newRow = {nomAtribut: "",tipus: "",mida: "",prioritat: "",obligatori: "",observacions: ""};
$scope.atributs.push(newRow);
}
查看:
<table class="table">
<tr>
<td>Nom atribut</td>
<td>Tipus</td>
<td>Mida</td>
<td>Prioritat</td>
<td>Obligatori</td>
<td>Observacions</td>
</tr>
<tr ng-repeat="atribut in atributs">
<td><input type="text" ng-model="atribut.nomAtribut" /> </td>
<td>
<select ng-options="option as option.valor for option in options" ng-model="atribut.tipus"></select>
</td>
<td><input type="number" ng-model="atribut.mida" /></td>
<td>
<select ng-options="option as option.valor for option in options" ng-model="atribut.tipus"></select>
</td>
<td><input type="checkbox" ng-model="atribut.obligatori" ng-true-value="'YES'" ng-false-value="'NO'"></td>
<td><input type="text" ng-model="atribut.observacions" /> </td>
</tr>
</table>
用于向 Web 服务发送数据的 Angular 代码:-
$scope.sendRow = function(){
$http.post("http://10.0.203.73/WS/ws.php/tipusactius/alta", $scope.atributs).success(function(data){
$scope.status = data;
})
}
Json 数组发送:-
[{"nomAtribut":"j",
"tipus":{"idvalors_combo":"3","valor":"Date"},
"mida":11,"prioritat":"",
"obligatori":"YES",
"observacions":"fcefwq"}]
一切都正确并且问题来自网络服务吗?还是角码错了?这是我第一次尝试使用 Angular。谢谢。
【问题讨论】:
-
编辑:网络服务需要一个 JSON 对象,不知道这是否有帮助
-
听起来您需要做的第一件事是打开开发工具并检查服务调用是否返回任何错误。如果不是,请检查网络选项卡并检查响应以查看它是否返回了您期望的格式。
-
我还要指出,您发布的数据是一个数组,在技术上不是 json 对象
-
是的,我正在发送一个数组,但我不知道为什么。如何转换它?
-
我不能告诉你它需要什么,你需要知道网络服务期望什么。也许像
requestData = {someParamNameThatTheServiceExpects: $scope.atributs}
标签: javascript angularjs json web-services