4

我选择了 ng-repeat:

<select class="span5 ui-select2 id="goal_{{goal.id}}" multiple="multiple">
  <option ng-repeat="counterGoal in counterGoals" value="{{counterGoal.id}}">{{counterGoal.name}}</option>
</select>

goal模型中我有counter_goal_ids[1,2,3,4,5,6]. 如何选择包含在 中的选项goal.counter_goal_ids

4

1 回答 1

9

尝试以下操作:

您可以使用模型中的ng-selected属性和自定义函数来选择选项

ng-selected="isInGoalIds({{counterGoal.id}})"

在你的模型中,添加一个函数

$scope.isInGoalIds = function(id){
    angular.forEach($scope.counter_goal_ids, function(value, index){
      if(id == value){
        return true;
      }
    });
    return false;
}
于 2012-10-30T14:09:34.580 回答