我收到如下響應,我想調整select option
標記中的值。如何設置這些請建議相同如何使用angularjs在選擇選項字段中設置值
[null,"a","b","c ","d"]
我的代碼是這樣
$http.get('v1/sport').success(function(data) {
$scope.sports = [];
//$scope.sports = data.data;
angular.forEach(data.data, function(value, key) {
$scope.sports[value.sport_id] = value.name;
});
});
鑑於
<select name="teamSport"
ng-model="player.sport_id"
ng-options="sport[player.sport_id] as sport[player.name] for sport in sports"
ng-change="changedSport()"
required>
<option value="" selected="selected">-- Select --</option>
</select>
這裏角度選擇文檔HTTP s://docs.angularjs.org/api/ng/directive/select – MasoodUrRehman
請分享您的HTML文件?也分享$ scope.sports數據 –
您有沒有查看 {「sport_id」:「1」,「name」:「 「sport_id」:「2」,「name」:「b」},{「sport_id」:「3」,「name」:「c」},{「sport_id」:「4」,「名稱「:」d「}] || {「sport_id」:「3」,「name」:「c」} 打電話給我,我得到 {{sports}} || {[sports.sport_id]}} – Priya