今天學(xué)習(xí)了一下Angular中ng-options下拉數(shù)據(jù)默認(rèn)值的設(shè)定方法,留個(gè)筆記
直接上代碼
<div class="form-group"> <label class="col-sm-2 control-label">教師</label> <div class="col-sm-10"> <select style="display:block; width:100%; height:34px; padding:6px 12px; font-size:14px; line-height:1.4; border-radius:4px; border:1px solid #ccc; color:#555; " ng-model="editCourse.TeacherName" ng-options="Teacher.UserName for Teacher in TeacherList" required> <option value="">選擇教師</option> </select> </div> </div>
AngularJS
    //data為課程的編號(hào)ID   $scope.Edit = function (data) {      //通過課程ID獲取課程對(duì)象      CourseService.getByCourseID(data).then(function (result) {        $scope.editCourse = result.data;        //默認(rèn)值設(shè)定        //先通過課程里面的教師ID獲取教師對(duì)象        CourseService.GetTeacherByTeacherID(result.data.TeacherID).then(function (result) {         //$scope.TeacherList為所有教師的列表          for (i = 0; i < $scope.TeacherList.length; i++) {            //如果當(dāng)前課程教師的ID與當(dāng)前遍歷到的教師的ID相等的話就把當(dāng)前遍歷到的這個(gè)教師的對(duì)象給到 ng-model="editCourse.TeacherName"            if (result.data.UserID == $scope.TeacherList[i].UserID) {              $scope.editCourse.TeacherName = $scope.TeacherList[i];            }          }        });        angular.element("#edit").modal({          show: true        })      })    }演示

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注