simulationUI

SimulationUI 自定义下拉列表之二结构渲染

在上一篇中介绍了 simulationSelect 自定义下拉列表的概设,整个组件的设计自定义下拉列表之概设,接下来该篇将详细讲解并编写具体功能逻辑代码。

SimulationSelect组件主要代码回顾

;(function (win, undef) {
    // IIFE 匿名立即函数
    var SimulationSelect = function (config) {
        this.config = Object.assign({
            data: []
        }, config)
        this.el = document.querySelector(this.config.el)
        this.options = []
        this.options.selectedIndex = 0
        this.value = ''
        this.init() // 新增,初始化函数调用
    }
    SimulationSelect.prototype = {
        constructor: SimulationSelect,
        init: function () {
            this.render()
            this.bindEvent()
        },
        render: function () {},
        bindEvent: function () {},
        destroy: function () {}
    }
    win.SimulationSelect = SimulationSelect
}(window, void 0))

// 调用方式
var simSelect = new SimulationSelect({
    el: 'selector'
})

init 初始化函数

首先,init 初始化函数中包含两个功能,DOM节点render渲染以及bindEvent事件绑定,该方法的调用可以方便地放在构造函数中。

render DOM节点渲染函数