创建自定义元素
要向 lightbox 添加自定义控件,你可以如下定义一个新对象:
gantt.form_blocks["my_editor"]={
render:function(sns){ //sns - 区块的配置对象
return "html code of the editor here";
},
set_value:function(node,value,task,section){
//node - 上述定义的 html 元素
//value - 由 map_to 属性定义的值
//task - 任务对象
//section- 区块的配置对象
... code to set value to the element ...
},
get_value:function(node,task,section){
//node - 上述定义的 html 元素
//task - 任务对象
//section - 区块的配置对象
return "current value from editor";
},
focus:function(node){
//node - 上述定义 的 html 元素
...code to set focus to the element...
}
}
请注意,在 "render" 函数返回的 HTML 代码中不要使用自闭合标签,否则可能会在部分浏览器中导致解析问题:
//这是错误的写法
render:function(){
return "<div id='box'/>";
}
//正确做法,请使用成对的开始和结束标签:
render:function(){
return "<div id='box'></div>"; // 推荐
}
Custom control in the lightbox
lightbox 控件包含以下方法:
- render (sns): string - 返回包含该区块 HTML 元素的字符串
- sns - (LightboxSection) - 区块的配置对象
- set_value (node, value, task, section): any - 从 Task 对象获取值并应用到区块
- node - (HTMLElement) - 与区块 HTML 相关的元素
- value - (any) - 由 map_to 属性定义的值
- task - (Task) - 任务对象
- section - (LightboxSection) - 区块的配置对象
- get_value (node, task, section): any - 从区块获取值并保存回 Task 对象
- node - (HTMLElement) - 与区块 HTML 相关的元素
- task - (Task) - 任务对象
- section - (LightboxSection) - 区块的配置对象
- focus (node): void - 设置区块的焦点
- node - (HTMLElement) - 与区块 HTML 相关的元素