我有一個包含一些信息的多行的表。用戶可以選擇他們想要的行數(使用每行中的複選框),並且在他們選擇(或取消選擇)行時,我希望totalSelected
被更新。在Vue.js中綁定多個數字文本框
我的視圖模型目前看起來是這樣的:
var viewModel = new Vue({
el: "#OrderPickContainer",
data: {
ProductTitle: "",
Batches: [],
totalSelected: 0
},
methods: {
// I have some unrelated methods here
}
});
我的表看起來像這樣:
<table class="table table-striped">
<thead>
<tr>
<th>Select</th>
<th>Batch Number</th>
<th>Available</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<template v-for="batch in Batches">
<tr>
<td><input type="checkbox" /></td>
<td>{{ batch.BatchNumber }}</td>
<td>{{ batch.AvailableQuantity }}</td>
// This is the input that I would like to bind to update `totalSelected`. The issue though is there are multiple rows with this exact input and I want them all to be able to add or subtract to the total.
<td><input type="number" min="0" class="form-control" /></td>
</tr>
</template>
<tr>
<td></td>
<td></td>
<td><strong>Total:</strong></td>
<td><strong>{{ totalSelected }}</strong></td>
</tr>
</tbody>
</table>
所以,因爲有多個行,我遇到的問題是搞清楚如何將所有這些數字文本框綁定到一個Vue變量。
感謝您解決完整的問題:) – Quiver