0

我希望将动态选择选项值绑定到选择下拉列表。ng-repeat中的动态选择选项

​​

我喜欢

age in ageConditions 

是动态的。我也试过ng-options =“dynamicOptions”,但它总是绑定到同一个列表。

我想用ng-repeat来实现这一点。

Repeat 1: 
    <select ng-model="condition.Description" class="form-control"> 
      <option value="">- Select -</option> 
      <option ng-value="ageCondition1">ageCondition1</option> 
      <option ng-value="ageCondition2">ageCondition2</option> 
    </select> 
    Repeat 2: 
    <select ng-model="condition.Description" class="form-control"> 
      <option value="">- Select -</option> 
      <option ng-value="yearsCondition1">yearsCondition1</option> 
      <option ng-value="yearsCondition2">yearsCondition2</option> 
    </select> 

如图所示,我希望select中的选项在ng-repeat中是动态的。 有什么想法?

+0

仍然没有得到你想要的动态...你可以展示一些真实的数据,然后它应该如何显示,运动员 – harishr 2014-11-21 04:59:19

+0

@harish,我希望select中的选项是动态的,但不能让它工作在NG-重复。显示不同选项的两个选择块。 – ove 2014-11-21 05:02:42

+0

但是有多少次重复和什么是什么逻辑的哪个字段被显示时?是固定为2,如果是的话那么为什么选择ng-repeat ...需要很多清晰的要求 – harishr 2014-11-21 05:05:02

回答

0

解决了这个。

0
 <select ng-model="condition.Description" class="form-control"> 
       <option value="">- Select -</option> 
       <option value="getValue(age, $parent.$index)" ng-repeat="age in ageConditions">    getText(age, $parent.index)</option> 
     </select> 

请注意使用$ parent。$ index。 动态性van实现使用函数返回基于$ index的值。

 $scope.getValue = function(age, index) { 
      if(index === 1) return age.Desciption else age.years; 
     } 


     $scope.getText = function(age, index) { 
      if(index === 1) return age.Desciption else age.years; 
     } 

希望这种通过创建创造了一个新的余地选择一个指令帮助

+0

但我希望ng-repeat的ageConditions是动态的。 – ove 2014-11-21 05:31:49

+0

条件可以根据来自数据库的内容而改变 – ove 2014-11-21 05:32:28

+0

鉴于这是一项功能。逻辑在你手中。让它像你想要的那样动态。 – harishr 2014-11-21 05:34:12