gpt4 book ai didi

javascript - Ionic Framework/AngularJS 中的两组单选按钮

转载 作者:数据小太阳 更新时间:2023-10-29 04:08:02 24 4
gpt4 key购买 nike

我有两组具有相同值的单选按钮。其中一个是用户输入,一个是用于显示之后的结果。

我能够正确保存这些值,但问题是任何时候只有一个单选按钮显示为事件按钮。我真正想要的是让每个 radio 都处于事件状态。

应用程序.js:

angular.module('starter', ['ionic', 'starter.controllers'])

.config(function($stateProvider, $urlRouterProvider) {

// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider

// setup an abstract state for the tabs directive
.state('tab', {
url: "/tab",
abstract: true,
templateUrl: "templates/tabs.html"
})

.state('tab.dash', {
url: '/dash',
views: {
'tab-dash': {
templateUrl: 'templates/tab-dash.html',
controller: 'DashCtrl'
}
}
})

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/tab/dash');

});

controllers.js:

angular.module('starter.controllers', [])

.controller('DashCtrl', function($scope, $window, $ionicPlatform) {

$ionicPlatform.ready(function() {
// Ready functions
});

$scope.grossOptionsList = [
{ text: "Year", value: "year" },
{ text: "Month", value: "month" },
{ text: "Week", value: "week" },
{ text: "Day", value: "day" }
];

$scope.resultsOptionsList = [
{ text: "Year", value: "year" },
{ text: "Month", value: "month" },
{ text: "Week", value: "week" },
{ text: "Day", value: "day" }
];

// Default values
$scope.data = {};
$scope.data.grossOptions = 'year';
$scope.data.resultOptions = 'month';


$scope.updateGrossOptions = function(item) {
console.log( 'Gross option: ' + item.value );
}

$scope.updateResultOptions = function(item) {
console.log( 'Results option: ' + item.value );
}

})

tab-dash.html:

<ion-view title="Salary Calculator">
<ion-content class="has-header">

<div class="button-bar padding">

<ion-radio ng-repeat="item in grossOptionsList"
ng-value="item.value"
ng-model="data.grossOptions"
ng-change="updateGrossOptions(item)"
class="button button-positive button-outline">
{{ item.text }}
</ion-radio>

</div>

<div class="list list-inset">

<div class="item item-divider">
Results per {{ data.resultOptions }}
</div>

<div class="button-bar padding row item">

<ion-radio ng-repeat="item in resultsOptionsList"
ng-value="item.value"
ng-model="data.resultOptions"
ng-change="updateResultOptions(item)"
class="button button-positive button-outline">
{{ item.text }}
</ion-radio>

</div>

</div>

</ion-content>
</ion-view>

Demo plnkr showing here我可以为每个单选按钮组设置值,但我想为每个组设置一个值(即输入月份和结果日期)。

最佳答案

没关系!我只是没有为这两个组设置 name 值。叹息。

关于javascript - Ionic Framework/AngularJS 中的两组单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25103883/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com