【问题标题】:Keydown event in angular-selectize?角度选择中的按键事件?
【发布时间】:2015-03-22 22:26:44
【问题描述】:

like this 怎么能用angular-selectize 实现?

我在监听按键事件时遇到问题。该示例使用 selectize.$control_input.on("keydown"),但在 angular-selectize 中似乎没有任何此类内容。

【问题讨论】:

    标签: javascript angularjs angularjs-directive selectize.js


    【解决方案1】:

    angular-selectize 暴露了 onInitialize 中的原生 Selectize 实例:

            onInitialize: function(selectize)
            {
                $scope.selectize = selectize;
            }
    

    例如。

    【讨论】:

      【解决方案2】:

      您也可以通过 selectize 插件来实现。

      活动报名见文末。

      /**
       * Plugin: "dropdown_header" (selectize.js)
       * Copyright (c) 2013 Brian Reavis & contributors
       *
       * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
       * file except in compliance with the License. You may obtain a copy of the License at:
       * http://www.apache.org/licenses/LICENSE-2.0
       *
       */
      
      Selectize.define('dropdown_header', function(options) {
      	var self = this;
      
      	options = $.extend({
      		title         : 'Untitled',
      		headerClass   : 'selectize-dropdown-header',
      		titleRowClass : 'selectize-dropdown-header-title',
      		labelClass    : 'selectize-dropdown-header-label',
      		closeClass    : 'selectize-dropdown-header-close',
      
      		html: function(data) {
      			return (
      				'<div class="' + data.headerClass + '">' +
      					'<div class="' + data.titleRowClass + '">' +
      						'<span class="' + data.labelClass + '">' + data.title + '</span>' +
      						'<a href="javascript:void(0)" class="' + data.closeClass + '">&times;</a>' +
      					'</div>' +
      				'</div>'
      			);
      		}
      	}, options);
      
      	self.setup = (function() {
      		var original = self.setup;
      		return function() {
      			original.apply(self, arguments);
      			self.$dropdown_header = $(options.html(options));
      			self.$dropdown.prepend(self.$dropdown_header);
      
      			this.$control.on('keydown', function(e) {
      				//alert('A keypess $control!');
      			});
      			this.$wrapper.on('keydown', function(e) {
      				//alert('A keypess $wrapper!');
      			});
      			this.$input.on('keydown', function(e) {
      				alert('A keypess $input!');
      			});
      		};
      	})();
      
      });

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-07
        • 2015-05-28
        • 2018-06-09
        • 2021-09-28
        • 1970-01-01
        • 1970-01-01
        • 2020-05-28
        相关资源
        最近更新 更多