2016-10-28 95 views

回答

2

您正在使用jQuery插件在AngularJS,您可以通过调用与元素绑定一个指令的功能,使用它,如下图所示:

HTML:

<select class="selectpicker" bootstrap-selectpicker data-ng-model="modelValue" multiple="" data-actions-box="true"> 
<option>Mustard</option> 
<option>Ketchup</option> 
<option>Relish</option> 
</select> 

指令:

app.directive('bootstrapSelectpicker'), function(){ 
var bootDirective = { 
    restrict : 'A', 
    link: function(scope, element, attr){ 
     $(element).selectpicker(); 
    }   
}; 
    return bootDirective; 
}); 

但我会建议使用基于Angularjs的dropwdowns,看看下面的插件。

http://isteven.github.io/angular-multi-select/#/main

http://angular-ui.github.io/ui-select/

http://ngmodules.org/modules/angular-bootstrap-multiselect https://github.com/dotansimha/angularjs-dropdown-multiselect

希望这有助于:)

+0

非常感谢! – Patres

0

我在option标签与ng-repeat工作。对于我每次运行以下功能,每次获得新数据都会执行以下任务:

function selectPickerRefresh() { 
    $timeout(function() { 
     $scope.$digest(); 
     $('.selectpicker').selectpicker('refresh'); 
    }); 
}