我的观点是:
<div class="well well-sm" ng-repeat="item in receivingItems">
{{ item.sku }}: {{ item.description }}<br />
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="col-sm-2 control-label">Quantity</label>
<div class="col-sm-10">
<input type="number" class="form-control" placeholder="">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Lot</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="">
</div>
</div>
</form>
</div>
<form class="form-inline" role="form">
<div class="form-group">
<label class="sr-only">SKU</label>
<input type="text" ng-model="receivingValue" placeholder="SKU" typeahead="sku for sku in getSku($viewValue) | filter:$viewValue" typeahead-on-select="selectedSku()" class="form-control" autocomplete="off" autocapitalize="off">
</div>
</form>
在我的控制器中,我有:
$scope.selectedSku = function() {
var sku = $scope.receivingValue.split(':')[0];
ItemService.getBySku(CompanyService.getCompany()._id, $scope.selectedClient._id, sku).then(function(response) {
$scope.receivingItems.push(response.data.item);
$scope.receivingValue = null;
});
}
所以这符合您的预期。当您搜索 SKU 时,它会创建一个带有数量和批次字段的新表单。但是现在当我提交整个表单时,我希望以某种方式存储和保存这些值。那么我如何使用ng-model
(或者我不必?)动态字段元素?