本帖最后由 Ellia.Duan 于 2024-4-15 17:25 编辑
调研编号:SJS-23771
LastReview:2024-4-15
以下是我想做的一个容器实例,如果我想要在配置的时候支持children,children中书写基础组件类型能够正常渲染,如下图所示,那么,在组件自定义的过程中我应该怎么操作呢?
import GC from '@grapecity/spread-sheets-designer'
// 构建组件类结构
function defineComponent() {
function CustomCompFn() {
GC.Spread.Sheets.Designer.AtomicComponentBase.call(this, ...arguments)
}
CustomCompFn.prototype = new GC.Spread.Sheets.Designer.AtomicComponentBase()
// 此函数用于定义组件的innerHTML
CustomCompFn.prototype.getTemplate = function () {
console.log('是否获取模板')
return `
<div class="mg-flex-list"></div>
`
}
CustomCompFn.prototype.onInit = function () {}
// 现在主机元素已经附加到DOM中,您可以向其中添加事件侦听器
CustomCompFn.prototype.onMounted = function (host) {
host.style.cssText = this._options.style || ''
this._eventListener = function (e) {
console.log('点击事件', e)
}
console.log('onMounted', host)
// 对每个list元素添加事件
// document.getElementsByClassName('mg-flex-list')
}
CustomCompFn.prototype._attachEvent = function () {
var r = this
this.host.addEventListener('click', this._eventListener)
}
CustomCompFn.prototype.onValueChanged = function (prevValue, nextValue, host) {}
// 此函数将在raiseValueChanged()之后调用
CustomCompFn.prototype.updateValue = function (host) {}
// 解除事件的绑定
CustomCompFn.prototype.onDestroy = function (host) {
// 销毁事件
this.host.removeEventListener('click', this._eventListener)
}
return CustomCompFn
}
const MgFlexContainer = defineComponent()
GC.Spread.Sheets.Designer.Designer.RegisterComponent('MgFlexContainer', MgFlexContainer)
|