如何在編輯項目時設置下拉菜單的選定值?angularjs - 編輯項目時在選擇下拉菜單中設置選定的值
<div class="form-group">
<label for="category" class="col-sm-2 control-label">Category</label>
<div class="col-sm-10">
<select ng-model="quiz.category" ng-options="category as category.name for category in categories" required>
<option></option>
</select>
</div>
</div>
當我點擊編輯
$scope.editQuiz = function(quiz)
{
$scope.quiz = {};
$scope.quiz.name = quiz.name // this works fine
$scope.quiz.category = quiz.category[0]; // ?????
console.log($scope.quiz.category);
//$scope.quiz = quiz;
}
方法來獲得類別:
$scope.getCategories = function() {
$http.get('http://localhost/myappi/API/index.php/Api/categories').
success(function(data) {
$scope.categories = data;
})
.error(function(err) {
console.log('error',err);
})
};
只是'quiz.category' – koox00
quiz.category會給我的Array [1],quiz.category [0]會給我的對象。忘了提及。 – Cristian
你有多個選擇? – koox00