我在兩個表中顯示兩個json文件數據。我能夠console.log()
所選的每一行的值。我提交了一個提交按鈕,但我不知道如何獲得這些兩個值來提交它。有人可以幫助我理解如何做到這一點?如何在angularjs中提交沒有表單的單選框值
下面是我的兩個表
<div class="row">
<div class="col-md-8">
<h1>Choose your outbound</h1>
<table class="table">
<tr>
<th>Departure</th>
<th>Arrival</th>
<th>Economy class</th>
<th>Business class</th>
<th>First class</th>
<th></th>
</tr>
<tr ng-repeat="outbound in outbounds" ng-class="{active : isSelected(outbound)}" ng-click="setMaster(outbound)">
<td>{{ outbound.departure }}h</td>
<td>{{ outbound.arrival }}h</td>
<td>{{ outbound.ecoPrice }}</td>
<td>{{ outbound.businessPrice }}</td>
<td>{{ outbound.firstPrice }}</td>
<td>
<input type="radio" name="radioOutbound">
</td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col-md-8">
<h1>Choose your inbound</h1>
<table class="table">
<tr>
<th>Departure</th>
<th>Arrival</th>
<th>Economy class</th>
<th>Business class</th>
<th>First class</th>
<th></th>
</tr>
<tr ng-repeat="inbound in inbounds" ng-class="{active : isSelected(inbound)}" ng-click="setMaster(inbound)">
<td>{{ inbound.departure }}h</td>
<td>{{ inbound.arrival }}h</td>
<td>{{ inbound.ecoPrice }}</td>
<td>{{ inbound.businessPrice }}</td>
<td>{{ inbound.firstPrice }}</td>
<td>
<input type="radio" name="radioInbound">
</td>
</tr>
</table>
<button type="submit" ng-click="submit()">Submit</button>
</div>
</div>
下面是我AngularJS
// Inbound
$scope.isSelected = function(inbound) {
return $scope.selected === inbound;
}
$scope.setMaster = function(inbound) {
$scope.selected = inbound;
console.log($scope.selected);
}
// Outbound
$scope.isSelected = function(outbound) {
return $scope.selected === outbound;
}
$scope.setMaster = function(outbound) {
$scope.selected = outbound;
console.log($scope.selected);
}
// Submit
$scope.submit = function() {
console.log($scope.selected);
}
創建'$ scope.submit()'函數在控制器中。將您登錄到控制檯的數據發送到您想要的方法。 – Georgy
也不需要兩個'$ scope.isSelected()'函數,你可以留下一個。 – Georgy
@Georgy我用你的解決方案更新了我的代碼。我現在唯一的問題是,我只有最後一個電臺選擇的價值。如何獲得兩個電臺的價值? – maevy