【发布时间】:2015-10-02 23:09:28
【问题描述】:
我有一种情况,我有一个表格,其中有一行,我有两个文本字段条目,我必须为该行上传一个文件,这种行可以是“N”然后有一个可以为整个表单输入的主文件,而这些是表单的一部分,我必须在单击保存按钮时立即提交所有这些文件。
我有点被 ng-upload 卡住了,它需要一个 api 调用,而且我真的不能对这个表单进行多个 api 调用。 示例 html 代码如下:
<!DOCTYPE html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<form editable-form name="xyzForm" ng-submit="create(model)">
<label>Tags: </label><input class="col-xs-12 col-md-12" ng-model="model.tags" type="text" name="Tags">
<label>Notes: </label> <input class="col-xs-12 col-md-11" ng-model="model.notes" type="text" name="notes">
<table class=" col-xs-3 col-md-11 table" border="1px solid red;">
<thead>
<tr>
<th>Product</th>
<th>Manufacturer</th>
<th>Location</th>
<th>Specification</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="itemRow in item.singleItem">
<td><input type="text" class="xdTextBox" name="itemRow.name" ng-model="model.itemRow[$index].name" /></td>
<td><input type="text" class="xdTextBox" name="itemRow.manufacturer" ng-model="model.itemRow[$index].manufacturer" /></td>
<td><input type="text" class="xdTextBox" name="itemRow.location" ng-model="model.itemRow[$index].location" /></td>
<td><i class="pull-left glyphicon glyphicon-upload"><input type="file" name="itemRow.doc" ng-model="model.itemRow[$index].doc" multiple=false></i></td>
<td><i class="pull-left glyphicon glyphicon-remove"></i></td>
</tr>
</tbody>
</span>
</table>
<label>Product Spec: </label><input type="file" ng-model="prefabdoc" multiple="true" ngf-maxsize="15000000" />
</form>
</body>
</html>
【问题讨论】:
-
不能使用
https://github.com/danialfarid/ng-file-upload吗? -
我在我的代码中已经使用了相同的东西,但是对如何同时为多个文件实现这个以及在表单中不同位置的不同文件集实现这一点感到困惑
-
这也是youtube上的一个很好的资源:@987654321@
-
@Bran Stark - 我正在努力实现您在上面的问题陈述中提到的内容。我是 Angular Js 的新手,我发现下面接受的答案有点接近,但仍然不清楚我该如何实现对于您上面提到的问题陈述。您能否分享您实现的代码,这将非常有帮助..谢谢。
-
接受的答案对你有用吗@BranStark?
标签: angularjs node.js sails.js multifile-uploader