我有以下代码。
<td class="minwd100">
<select class="form-control" id="invoice_id" name="invoice_id" ng-options="invoice as invoice.invoice_number+ ' - '+invoice.client_name+' - '+invoice.invoice_converted_total for invoice in approved_invoices track by invoice.invoice_id" ng-model="approved_invoices.invoice_id" ng-change="changeInvoice(approved_invoices.invoice_id)"></select>
</td>
<td class="minwd100"><input type="text" class="form-control" id="payment_amount" ng-model="payment_data.payment_amount.value" name="payment_amount" placeholder="Enter {{form_data.payment_amount.label}}" ng-focus="form_data.payment_amount.error = ''" /></td>
<td class="minwd100"><input type="text" class="form-control" id="payment_conversion" ng-model="payment_data.payment_conversion_rate.value" name="payment_conversion" placeholder="Enter {{form_data.payment_conversion_rate.label}}" ng-focus="form_data.payment_conversion_rate.error = ''" /></td>
<td class="minwd100"><input type="text" class="form-control" id="payment_converted_amount" ng-model="payment_data.payment_converted_amount.value" name="payment_converted_amount" placeholder="Enter {{form_data.payment_converted_amount.label}}" ng-focus="form_data.payment_converted_amount.error = ''" ng-readonly="true"/></td>
<td class="wd80">
<div class="dt-options">
<a href ng-if="$index === form.payments.length - 1" ng-click="addContact()" title="Add Contact"><i class="fa fa-plus fa-lg"></i></a>
<a href ng-if="form.payments.length > 1" ng-click="removeContact($index)" title="Remove Contact"><i class="fa fa-trash-o fa-lg"></i></a>
</div>
</td>
<script>
$scope.changeInvoice = function (selectedItem){
$scope.payment_data.payment_amount.value = selectedItem.invoice_converted_total;
$scope.payment_data.payment_conversion_rate.value = selectedItem.invoice_conversion_rate;
$scope.payment_data.payment_converted_amount.value = selectedItem.invoice_converted_balance;
$scope.client_id = selectedItem.client_id;
$scope.payment_data.invoice_id.value = selectedItem.invoice_id;
};
$scope.addContact = function() {
$scope.form.payments.push({invoice_id: '', payment_amount: '', payment_conversion: '', payment_converted_amount: ''});
};
$scope.removeContact = function(index) {
$scope.form.payments.splice(index, 1);
};
</script>
对于每个更改,应该为每个输入触发值,但是现在每当我添加新行时,它都会反映旧值本身,请提供帮助。我还添加了图片,请参考。
答案 0 :(得分:0)
什么是你迭代通过收集?
“对于每个更改,应该为每个输入触发值,但是现在每当我添加新行时,它都会反映旧值本身,请帮忙。我添加了图像,也请引用它。”
您是说当您更改一行时,每一行都会更改吗?这是怎么了理解它。我的猜测是,集合中的所有项目都引用同一个对象,您需要引用集合中的特定项目。
我最近建立了一个模型,该模型具有可以在其中添加许多关联的形式,因此在向该表单添加新关联时,我必须使用唯一键来引用哈希。即:
$scope.addNewPartToAssembly = function(part) {
$scope.form.assembly.assembly_parts[part.id] = {
...
}
}
我只是在猜测您的问题,因为对我而言,这似乎并不完整,也许其他人可以通过提供的内容解决它。无论哪种方式,希望对您有所帮助。