2015-04-01 56 views
1

我正在创建一个web应用程序,我使用引导selectpicker选择..但我使用angularjs来填充选择选择器..我有2选择一个内容的基础上填充无需重新加载..我能很好地工作它而不selectpicker虽然它不工作时使用selectpicker第一选择值..我的代码是Angularjs不工作在引导selectpicker

<div class="form-group" data-ng-controller="MARK_ENTRY_CONTROLLER"> 
    <div class="row"> 
     <div class="col-md-6 " style="margin-top: 7px;"> 
      <label>Select Class</label> 
     </div> 
     <div class="col-md-6 text-center"> 
      <select class="form-control" title="Select Class" 
       name="fromClass" ng-change="EXAM_LIST_JSON(fromClass)" 
       ng-model="fromClass" 
       ng-options="fromClass.id as fromClass.course + ' ' + fromClass.section for fromClass in ALL_CLASS"> 
       </select> 
     </div> 
    </div> 
    <div class="row" style="height: 10px"></div> 
    <div class="row"> 
     <div class="col-md-6 " style="margin-top: 7px;"> 
      <label>Select Examination</label> 
     </div> 
     <div class="col-md-6 text-center" > 
      <select class="form-control" name="examination" 
       ng-change="SUBJECT_LIST_IN_EXAM_JSON()" 
       ng-model="examination" 
       ng-options="examination.id as examination.name for examination in EXAM_LIST"></select> 
     </div> 
    </div> 

和控制器

<script> 
    function MARK_ENTRY_CONTROLLER($scope, $http) { 
     $http.get("<%=request.getContextPath()%>/ALL_CLASS_JSON?AAdvisorId=${uid}").success(function(response) { 
         $scope.ALL_CLASS = response; 
         $scope.EXAM_LIST_JSON = function(id){ 
     $http.get("<%=request.getContextPath()%>/EXAM_LIST_JSON?fromClass="+id) 
           .success(function(response) { 
            $scope.EXAM_LIST = response; 
            $scope.$apply(); 
          }); 
         } 

        }); 
    } 
</script> 

在这里,在控制器的数据的列表是从一个JSON文件使用JSON格式获得.. 请帮我..

回答

7

自举选,隐藏所有选择和数据选择,就多后来由于执行命令$('select')。selectpicker()。

但是如何解决这个问题呢?

我有一个类似的问题:

<select class="fontsize" data-style="btn-info" name="fontsize" ng-controller="fontSize"> 
    <option data-ng-repeat="size in sizes" name="{{size}}" value="{{size}}">{{size}}</option> 
</select> 

我的控制器

app.controller('fontSize', function($scope, $http) { 
    $http.get("/getSelector/font-size") 
     .success(function(response) { 
      $scope.sizes = response.records; 
      // TODO: How to refresh the selectpicker after changing of scope? 
     }); 
}); 

已接收到数据后,您可以刷新selectpicker:

$scope.$watch(function() { 
    $('.fontsize').selectpicker('refresh'); 
}); 

好吧,我希望这对你有帮助。

+0

你救了我的一天。谢谢! – Margaret 2016-09-23 12:57:22

+0

是否有可能不依赖于jQuery? – ellockie 2017-11-28 17:42:13