2015-05-14 44 views
0

裏面NG重複填充一定值下拉列表中,我有一個必須要充滿某些選定的值,如果沒有在obj.Name1數據選擇下拉否則應選擇在默認的第一個值選項。Angularjs,如選擇

<table ng-controller="TestCtrl"> 

<tr ng-repeat="obj in MainArray" > 
<td>{{$index + 1}}</td> 
<td ng-model="MainArray">{{obj.FirstValue}}</td> 
<td> 

<!-- if obj.Name1 has some value then it has to be selected in select dropdown, else default first value of dropdown must be displayed --> 
<!-- dont know how to put a condition so as to display the obj.Name1 value in the dropdown--> 

<select ng-model="DropdownArray[$index]" ng-options="test.ID as test.Name for test in DropdownList" > 
    <option>Default Value</option> 
</select> 

</table> 

//控制器

.controller('TestCtrl',function($scope, $rootScope, $http, URL, $state, $modal, $interval, Notification){ 



    $scope.DropdownArray=[]; 

    $scope.DropdownList=[ 
{"ID":"1","Name":"one"}, 
{"ID":"2","Name":"two"}, 
{"ID":"3","Name":"three"} 
]; 

    $scope.MainArray=[ 
{"FirstValue":"First","Name1":""} , 
{"FirstValue":"Second","Name1":"two"} , 
{"FirstValue":"Third","Name1":"one"}, 
{"FirstValue":"Forth","Name1":""} 
]; 

}) 

我的問題是,如果obj.Name1包含任何值,我怎麼能顯示它作爲選擇的選項?

+0

究竟什麼是你的問題? – AlexMA

+0

如果obj.Name1包含任何值,那麼我如何顯示它作爲選定的選項 例如,{「FirstValue」:「Second」,「Name1」:「two」} Name1的值爲2,顯示爲選定選項(在DropdownArray [$ index]中) – venkatesh52

回答

0

您可以匹配一個空字符串,而且由於內部ng-model變量不包含任何它將對空值相匹配的選項,如下所示

<select ng-model="DropdownArray[$index]" ng-options="test.ID as test.Name for test in DropdownList" > 
    <option value="">Default Value</option> 
</select> 
+0

如何在選擇下拉菜單中顯示obj.Name1值? (我需要DropdownArray []爲其他目的,基本上得到個人下拉值) – venkatesh52