• 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);

  • 相关阅读:
    C#用Infragistics 导入导出Excel
    C#基础---Attribute(标签) 和 reflect(反射) 应用二
    C#基础系列:反射笔记
    反射基础
    NPOI之Excel——合并单元格、设置样式、输入公式
    NPOI对Excel的操作(Sheet转DataTable、List<T>)
    【SVN版本回退】
    撤销修改
    iOS
    ios 排序汇总
  • 原文地址:https://www.cnblogs.com/wouldguan/p/3687918.html
Copyright © 2020-2023  润新知