componentContainer
引用名:componentContainer
说明:容器类,当组件内调用 setContainer 时,创建一组容器示例
componentContainer.prototype
function addComponent(meta, data, targetEl, opts)
说明:在容器内添加一个组件
参数说明:
meta:组件的配置数据,(即编写组件时的package.json文件以及editing.js文件数据)
data:组件数据,(即将组件拖入到预览窗口后产生的数据,这部分数据由用户产生)
targetEl:临时占位dom对象,在拖入预览窗口时,会有一个占位dom对象,如果没有,可传 null
opts:添加的组件的控制项,具体如下:
{
configurable: true,/*是否可配置*/
deletable: true,/*是否可以删除*/
movable: true /*是否可移动*/
}
function initComponents(components)
说明:通过一组组件数据,初始化容器,容器将遍历组件列表,将允许添加至容器的组件添加到容器框内
function eachSubComponents(fn)
说明:遍历容器内所有组件。
function getData()
说明:遍历容器内所有组件,将组件的配置数据整理为 Array 返回
示例
- 底板容器组件
/*
组件类定义。
*/
define(['jquery', 'configurableComponent'], function($, Component) {
'use strict';
return Component.extend({
renderView: function() {
this.setComponentContainer(
this.$viewEl.find('.sub_container').toArray(), "sub-container",
{
//在添加子组件之前执行,用于检查是否允许此组件被添加到子模块下。如果允许,返回true,否则返回false
acceptRole: function() {
return true;
}
}
);
}
});
});
