0
嗨,任何人都可以告訴我爲什麼我們需要使「(k,v)」在爲什麼我們需要在ng-option中配對是Angular的選擇。雖然我們可以使工作完成
ng-options =「k as v for(k,v)in types」因爲我們可以做的工作是通過編寫 ng-options =「k as v for v in types」來完成。
<div ng-app="myApp" ng-controller="myCtrl">
<p>Select a car:</p>
<select ng-model="selectedCar" ng-options="y.brand for (x, y) in cars">
</select>
<h1>You selected: {{selectedCar.brand}}</h1>
<h2>Model: {{selectedCar.model}}</h2>
<h3>Color: {{selectedCar.color}}</h3>
<p>The visible text inside the dropdown list can also be a property of the value object.</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.cars = {
car01 : {brand : "Ford", model : "Mustang", color : "red"},
car02 : {brand : "Fiat", model : "500", color : "white"},
car03 : {brand : "Volvo", model : "XC90", color : "black"}
}
});
喜你能提供運行的jsfiddle?爲了更好的理解。 –
我很抱歉,我認爲這會讓你感到很輕鬆,我無法正確解釋它。 – Kapein