這是select的html部分
<select class="form-control w-searchbar-select" ng-model="aa" ng-init="aa='請選擇設(shè)備狀態(tài)'" >
<option ng-repeat="data in ProcedureList" value="{{$index}}">{{data}}</option>
</select>
下面是定義的equipmentProcedureList部分
$scope.equipmentProcedureList = ["請選擇設(shè)備狀態(tài)", "注冊", "使用中", "故障", "報廢"];
目前的這種寫法頁面出現(xiàn)的效果是:
select框中沒有選中任何項,為空白狀態(tài)。
但是,如果去掉option 里的value="{{$index}}"后則會正常顯示。
求大神指點
想要達(dá)到的頁面效果就是默認(rèn)選中“請選擇設(shè)備狀態(tài)”,其余各項的value值為$index,最終采用的是ng-repeat實現(xiàn)了上述功能。$scope.equipmentProcedureList = ["請選擇設(shè)備狀態(tài)", "注冊", "使用中", "故障", "報廢"];
上面是selcect的下拉選項,預(yù)先定義好的。
$scope.aa="請選擇設(shè)備狀態(tài)";
這里指定默認(rèn)選中的項
<select class="form-control w-searchbar-select" ng-model="aa" >
<option value="請選擇設(shè)備狀態(tài)"></option>
<option ng-repeat="data in equipmentProcedureList" value="{{$index}}">{{data}}</option>
</select
這是HTML部分
angularJS推薦使用ng-options來創(chuàng)建下拉菜單
<select ng-model="aa" ng-options="y for (x, y) in ProcedureList"></select>
$scope.ProcedureList = ["請選擇設(shè)備狀態(tài)", "注冊", "使用中", "故障", "報廢"];
//我一般使用下面這樣初始化不用ng-init,這樣我覺得好改一點,想初始化幾就寫數(shù)組的索引
$scope.aa = $scope.ProcedureList[0];
option里面的value的值是數(shù)字,而初始化的話value='請選擇設(shè)備狀態(tài)',沒有對應(yīng)的顯示值與這個value..
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號