之前有个是自动补全下拉内容控件的需求,按照你们的帮助进行了实现代码如下:function AutocompleteCellType(availableTags) {
this.availableTags = [];
if (_.isArray(availableTags)) {
this.availableTags = availableTags;
}
}
AutocompleteCellType.prototype = new spreadNS.CellTypes.Base;
AutocompleteCellType.prototype.createEditorElement = function (context) {
return document.createElement('input');
};
AutocompleteCellType.prototype.activateEditor = function (editorContext, cellStyle, cellRect, context) {
var $editor = $(editorContext);
spreadNS.CellTypes.Base.prototype.activateEditor.call(this, editorContext, cellStyle, cellRect, context);
$editor.css('position', 'absolute');
$editor.attr('gcUIElement', 'gcEditingInput');
$editor.autocomplete({
minLength: 0,
source: this.availableTags
}).focus(function() {
$(this).autocomplete('search', $(this).val());
});
$editor.autocomplete('widget').attr('gcUIElement', 'gcEditingInput'); // keep focus when mouse down on dropdown
if(_.isEmpty($editor.val())){
$editor.autocomplete('search', '');
}
return $editor;
};
AutocompleteCellType.prototype.deactivateEditor = function (editorContext, context) {
if (editorContext) {
var $editor = $(editorContext);
$editor.autocomplete('destroy');
}
spreadNS.CellTypes.Base.prototype.deactivateEditor.call(this, editorContext, context);
};
AutocompleteCellType.prototype.setEditorValue = function (editorContext, value, context) {
$(editorContext).val(value);
};
AutocompleteCellType.prototype.getEditorValue = function (editorContext, context) {
return $(editorContext).val();
};
AutocompleteCellType.prototype.updateEditor = function (editorContext, cellStyle, cellRect, context) {
if (editorContext) {
var $editor = $(editorContext);
$editor.css('width', cellRect.width);
$editor.css('height', cellRect.height);
$editor.css('outline', 'none');
$editor.css('border', '0');
}
};
AutocompleteCellType.prototype.isReservedKey = function (event, context) {
var keyCode = _.get(event, 'keyCode');
return context.isEditing && (_.isEqual(keyCode, 38) || _.isEqual(keyCode, 40));
};目前碰到一个问题是希望像下图中的B21单元格一样,增加一个下拉选图标并绑定相关事件,应该如何做:
|