如何让这个应用多select?
How to make this app multi-select?
我想要下面 angularjs 这样的代码 example here。 "," 应添加在每个颜色 i select 之后。像这样 红白黑
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car:</p>
<select ng-model="selectedCar" ng-options="x.model for x in cars">
</select>
<h1>You selected: {{selectedCar.model}}</h1>
<p>Its color is: {{selectedCar.color}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.cars = [
{model : "Ford Mustang", color : "red"},
{model : "Fiat 500", color : "white"},
{model : "Volvo XC90", color : "black"}
];
});
</script>
</body>
</html>
选择框用于 'one select'
使用复选框
<div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre><code> <!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car:</p>
<span ng-repeat="x in cars">
<input type='checkbox' ng-model='x.checked'/>{{x.color}}
</span>
<h1>You selected: {{checkedModels()}}</h1>
<p>Its color is: {{checkedColors()}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope , $filter) {
$scope.cars = [
{model : "Ford Mustang", color : "red"},
{model : "Fiat 500", color : "white"},
{model : "Volvo XC90", color : "black"}
];
$scope.checkedColors = function(){
var checkedArr = $filter('filter')($scope.cars, {checked : true});
var text = '';
for(var i = 0 ; i < checkedArr.length ; i++) {
if(text.length != 0){text += ','}
text += checkedArr[i].color;
}
return text;
}
$scope.checkedModels = function(){
var checkedArr = $filter('filter')($scope.cars, {checked : true});
var text = '';
for(var i = 0 ; i < checkedArr.length ; i++) {
if(text.length != 0){text += ','}
text += checkedArr[i].model;
}
return text;
}
});
</script>
</body>
</html>
我想要下面 angularjs 这样的代码 example here。 "," 应添加在每个颜色 i select 之后。像这样 红白黑
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car:</p>
<select ng-model="selectedCar" ng-options="x.model for x in cars">
</select>
<h1>You selected: {{selectedCar.model}}</h1>
<p>Its color is: {{selectedCar.color}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.cars = [
{model : "Ford Mustang", color : "red"},
{model : "Fiat 500", color : "white"},
{model : "Volvo XC90", color : "black"}
];
});
</script>
</body>
</html>
选择框用于 'one select'
使用复选框
<div class="snippet" data-lang="js" data-hide="false" data-console="true">
<div class="snippet-code">
<pre><code> <!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car:</p>
<span ng-repeat="x in cars">
<input type='checkbox' ng-model='x.checked'/>{{x.color}}
</span>
<h1>You selected: {{checkedModels()}}</h1>
<p>Its color is: {{checkedColors()}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope , $filter) {
$scope.cars = [
{model : "Ford Mustang", color : "red"},
{model : "Fiat 500", color : "white"},
{model : "Volvo XC90", color : "black"}
];
$scope.checkedColors = function(){
var checkedArr = $filter('filter')($scope.cars, {checked : true});
var text = '';
for(var i = 0 ; i < checkedArr.length ; i++) {
if(text.length != 0){text += ','}
text += checkedArr[i].color;
}
return text;
}
$scope.checkedModels = function(){
var checkedArr = $filter('filter')($scope.cars, {checked : true});
var text = '';
for(var i = 0 ; i < checkedArr.length ; i++) {
if(text.length != 0){text += ','}
text += checkedArr[i].model;
}
return text;
}
});
</script>
</body>
</html>