handsontable的一种js继承方式

handsontable的一种js继承方式

注意: 部分核心代码如下:

管理类editors.js
(function (Handsontable) {
'use strict';

function RegisteredEditor(editorClass) {
var clazz, instances;

instances = {};
clazz = editorClass;

this.getInstance = function (hotInstance) {
  if (!(hotInstance.guid in instances)) {
    instances[hotInstance.guid] = new clazz(hotInstance);
  }

  return instances[hotInstance.guid];
}

}

var registeredEditors = {};

Handsontable.editors = {

/**
 * Registers editor under given name
 * @param {String} editorName
 * @param {Function} editorClass
 */
registerEditor: function (editorName, editorClass) {
  registeredEditors[editorName] = new RegisteredEditor(editorClass);
},

/**
 * Returns instance (singleton) of editor class
 * @param {String|Function} editorName/editorClass
 * @returns {Function} editorClass
 */
getEditor: function (editorName, hotInstance) {
  if (typeof editorName == 'function'){
    var editorClass = editorName;
    editorName = editorClass.toString();
    this.registerEditor(editorName, editorClass);
  }

  if (typeof editorName != 'string'){
    throw Error('Only strings and functions can be passed as "editor" parameter ');
  }

  if (!(editorName in registeredEditors)) {
    throw Error('No editor registered under name "' + editorName + '"');
  }

  return registeredEditors[editorName].getInstance(hotInstance);
}

};

})(Handsontable);
基类baseEditor.js
(function (Handsontable) {
'use strict';

function BaseEditor(instance) {
//this.prop = value

this.init();

}

BaseEditor.prototype.init = function(){};

BaseEditor.prototype.extend = function(){
var baseClass = this.constructor;
function Editor(){
baseClass.apply(this, arguments);
}

function inherit(Child, Parent){
  function Bridge() {
  }

  Bridge.prototype = Parent.prototype;
  Child.prototype = new Bridge();
  Child.prototype.constructor = Child;
  return Child;
}

return inherit(Editor, baseClass);

};

//BaseEditor.prototype.xxx = function(){}

Handsontable.editors.BaseEditor = BaseEditor;

})(Handsontable);

扩展类1checkboxEditor.js
(function(Handsontable){

//Blank editor, because all the work is done by renderer
var CheckboxEditor = Handsontable.editors.BaseEditor.prototype.extend();

CheckboxEditor.prototype.beginEditing = function () {
this.saveValue([
[!this.originalValue]
]);
};
CheckboxEditor.prototype.finishEditing = function () {};

CheckboxEditor.prototype.init = function () {};
CheckboxEditor.prototype.open = function () {};
CheckboxEditor.prototype.close = function () {};
CheckboxEditor.prototype.getValue = function () {};
CheckboxEditor.prototype.setValue = function () {};
CheckboxEditor.prototype.focus = function () {};

Handsontable.editors.CheckboxEditor = CheckboxEditor;
Handsontable.editors.registerEditor('checkbox', CheckboxEditor);

})(Handsontable);
扩展类2 dropdownEditor.js
(function (Handsontable) {

var DropdownEditor = Handsontable.editors.AutocompleteEditor.prototype.extend();

DropdownEditor.prototype.prepare = function () {
Handsontable.editors.AutocompleteEditor.prototype.prepare.apply(this, arguments);

this.cellProperties.filter = false;
this.cellProperties.strict = true;

};

Handsontable.editors.DropdownEditod = DropdownEditor;
Handsontable.editors.registerEditor('dropdown', DropdownEditor);

})(Handsontable);
扩展类2,3,4,5……

使用方法
var editorClass = instance.getCellEditor(cellProperties);
activeEditor = Handsontable.editors.getEditor(editorClass, instance);

转载于:https://www.cnblogs.com/wouldguan/p/3687918.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值