【发布时间】:2015-05-12 05:04:43
【问题描述】:
我正在处理一个动态表单,其中数据可以是多个路径,其他数据在保存时需要向服务器发送多个发布请求。这在角度上可能吗? 这是我的html,
<fieldset class="form-group pl-sm" ng-repeat="file in files">
<div>
<input type="text" class="form-control" autocomplete="off" name="fileLocation" ng-model="file.name">
</div>
<input type="checkbox" class="switch-input" name="" ng-model="file.xxxx" />
<input type="checkbox" class="switch-input" name="" ng-model="file.yyyy" />
<div class="col-sm-3">
<select class="form-control" name="fileCenters" ng-model="file.centers" required>
<option value="Development">Development</option>
<option value="Sales">Sales</option>
</select>
</div>
</fieldset>
<a href="" ng-click="addNew()">Add more </a>
我不确定如何将所有路径保存在单个发布请求中。所以本质上它必须是一个包含多个对象的 json 对象,例如
[{
location: 'france',
xxxx: true,
yyyy: false,
center: 'sales'
},
{
location: 'france',
xxxx: true,
yyyy: false,
center: 'sales'
}]
关于 angular http.post 的多个请求的任何帮助都会很棒,我是否需要将请求排队等待超时或添加回调并在第一个请求成功时链接请求??
【问题讨论】:
-
如果可以,将数组作为数据在单个请求中发送
$http.post(url, arrayOfObjects) -
您需要按特定顺序发送它们吗?如果不是,为什么你不能继续向服务器发出请求。
-
我真的不需要按一定的顺序发送它们,只是在表格上,只有一个保存按钮,点击保存后,所有位置都应该发布到服务器。 @YangLi,我将如何继续触发请求?
-
为什么不能有一个处理所有数据的路径而不是发送多个请求?
-
举个例子肯定会有帮助。
标签: javascript angularjs rest http-post