首页 > 代码库 > AnjularJs-Select添加数据并设置默认值

AnjularJs-Select添加数据并设置默认值

html中

<select name="book_classify" class="all_list_btn" ng-model="selectedBook" ng-options="x.id as x.bookName for x in bookList" ng-change="bookSelect(selectedBook)">
</select>

js中

$scope.bookList = data.objectList;              //[{bookName:"哈哈",id:23},{bookName:"嘿嘿",id:25}]
$scope.bookList.unshift({
"bookName":"全部书籍"});      //在开始位置添加一行数据
$scope.selectedBook
=$scope.bookList[0].id;         //设置默认值为第一个
$scope.bookSelect=function(bookid){
    console.log(bookid)
}

 

AnjularJs-Select添加数据并设置默认值