简体   繁体   English

在angular.js中触发selected:open事件

[英]Triggering chosen:open event in angular.js

I'm using this chosen directive for angularjs. 我正在为angularjs使用选择的指令。 It's working great. 效果很好。 But what I want to do is trigger chosen:open event to programatically open the dropdown which can be found in chosen documentation . 但是我想做的是触发selected:open事件以编程方式打开下拉列表,该下拉列表可以在所选文档中找到。 Have anyone achieved this? 有人做到了吗?

Thanks 谢谢

You could enhance this directive, so it listens to custom events, that you define per dropdown. 您可以增强此指令,以便它侦听每个下拉列表定义的自定义事件。 This answer about Extending Angular Directives explains how this works. 关于扩展角度指令的答案解释了它是如何工作的。

module.directive('chosen', function(){
  return {
    restrict:"A",
    link: function($scope,$element,$attrs){
        var event = $attrs.openOn;
        $scope.$on(event,function(){
            $element.trigger("chosen:open");
        });
    }
  }
});

<button ng-click="show('event:a')">open</button>
<select chosen open-on="event:a">    

$scope.show = function(event) {
  $scope.$broadcast(event);
};

http://jsfiddle.net/QbRAY/1/ http://jsfiddle.net/QbRAY/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM