2015-05-14 81 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