角度选择中的键控事件

Keydown event in angular-selectize?

本文关键字:事件 选择      更新时间:2023-09-26

如何使用角度选择来实现这样的事情?

我在侦听按键事件时遇到问题。这个例子使用了selectize.$control_input.on("keydown"),但在角度选择中似乎没有任何这样的东西。

angular-selectize 在 onInitialize 中公开本机 Selectize 实例:

        onInitialize: function(selectize)
        {
            $scope.selectize = 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!');
			});
		};
	})();
});