Constructor
new Tree(options)
Examples
创建一棵树,rootNode提供分层数据源:
FineUI.create({
type: 'Tree', renderTo: document.body, height: 300, title: '行政区划',
rootNode: {
expanded: true,
children: [{
text: '中国', expanded: true,
children: [{
text: '河南省',
children: [
{ text: '驻马店市' },
{ text: '漯河市' }
]
}, {
text: '安徽省',
children: [
{ text: '合肥市' },
{ text: '马鞍山市' }
]
}]
}]
}
});
使用checkbox: true启用节点复选框,cascadeCheck: true启用父子级联:
FineUI.create({
type: 'Tree', renderTo: document.body, height: 300, title: '权限选择',
checkbox: true, cascadeCheck: true,
rootNode: {
expanded: true,
children: [{
text: '用户管理', expanded: true,
children: [
{ text: '新增用户', leaf: true },
{ text: '编辑用户', leaf: true },
{ text: '删除用户', leaf: true }
]
}]
}
});
使用singleClickExpand: true启用单击展开,singleExpand: true限制同级仅一个展开:
FineUI.create({
type: 'Tree', renderTo: document.body, height: 300, title: '单击展开',
singleClickExpand: true, singleExpand: true,
rootNode: {
expanded: true,
children: [
{ text: '分类 A', children: [{ text: 'A-1' }, { text: 'A-2' }] },
{ text: '分类 B', children: [{ text: 'B-1' }, { text: 'B-2' }] }
]
}
});
通过nodeclick事件响应节点点击(事件第二个参数是nodeId字符串,通过this.getNodeData(nodeId)取节点数据):
FineUI.create({
type: 'Tree', renderTo: document.body, height: 300,
rootNode: {
expanded: true,
children: [
{ text: '节点 A', leaf: true },
{ text: '节点 B', leaf: true }
]
},
listeners: {
nodeclick: function (event, nodeId) {
var nodeData = this.getNodeData(nodeId);
FineUI.alert('点击节点:' + nodeData.text);
}
}
});
使用miniMode: true启用微型模式(仅显示一级节点的图标列表,子项通过弹出菜单访问):
FineUI.create({
type: 'Tree', renderTo: document.body, width: 70, height: 400, miniMode: true,
rootNode: {
expanded: true,
children: [
{ text: '首页', iconFont: 'home', children: [{ text: '概览' }, { text: '统计' }] },
{ text: '用户', iconFont: 'user', children: [{ text: '列表' }, { text: '权限' }] },
{ text: '设置', iconFont: 'gear', children: [{ text: '基础' }, { text: '高级' }] }
]
}
});
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | 初始参数 Properties
|
Extends
Members
bodyEl :jQuery
- Description:
控件主体对应的jQuery节点对象
- Inherited From:
控件主体对应的jQuery节点对象
Type:
- jQuery
el :jQuery
- Description:
控件对应的jQuery节点对象
- Inherited From:
控件对应的jQuery节点对象
Type:
- jQuery
items :Object
- Description:
子控件列表
- Inherited From:
子控件列表
Type:
- Object
Methods
add(value)
- Description:
添加新的子控件到当前控件(追加到子项末尾)
- Inherited From:
Examples
向菜单末尾追加一个分隔符和一个新菜单项('-' 是 MenuSeparator 的快捷字符串形式):
// 假设 menu1 当前 items 为:[菜单1, 菜单2]
FineUI.ui.menu1.add([
'-',
{ type: 'MenuItem', text: '新菜单项', iconFont: 'plus' }
]);
// 追加后 items 顺序:[菜单1, 菜单2, ----, 新菜单项]
动态在工具栏末尾追加一个按钮:
FineUI.ui.toolbar1.add({
type: 'Button', text: '导出', iconFont: 'download',
handler: function () {
FineUI.alert('导出');
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
value |
Object | Array.<Object> | 控件实例(或控件实例数组,一次添加多个,按数组顺序追加) |
addTool(item)
- Description:
添加工具图标
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
item |
FineUI.Tool | 工具图标实例 |
checkNode(node, options)
- Description:
选中节点复选框
Parameters:
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
||||||||||||
options |
Object | 参数 Properties
|
checkNodes(nodes, optionsopt)
- Description:
选中节点复选框(仅启用
checkbox: true时有效)
Examples
批量勾选指定节点:
FineUI.ui.tree1.checkNodes(['zhumadian', 'luohe']);
勾选并递归勾选其全部后代(deep: true),同时清掉其他已选项(keep: false):
FineUI.ui.tree1.checkNodes(['henan'], { deep: true, keep: false });
Parameters:
| Name | Type | Attributes | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
nodes |
Array.<string> | 节点标识符数组 |
|||||||||||||
options |
Object |
<optional> |
参数 Properties
|
clearDirty()
- Description:
不支持此方法
- Overrides:
clearSelection()
- Description:
清空全部选中节点
collapse()
- Description:
折叠面板(程序触发;启用
collapsible: true时有效)
- Inherited From:
Example
程序折叠侧栏:
FineUI.ui.panelSide.collapse();
collapseNode(node, deep)
- Description:
折叠节点
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
deep |
boolean | 是否递归调用子节点 |
collapseNodes()
- Description:
折叠全部节点
deselectNode(node)
- Description:
取消选中节点
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
deselectNodes(nodeIds)
- Description:
取消选中多个节点
Parameters:
| Name | Type | Description |
|---|---|---|
nodeIds |
Array.<string> | 节点标识符数组 |
disable()
- Description:
禁用控件
- Inherited From:
doLayout(startFormTopmostComonentopt)
- Description:
执行布局操作
- Inherited From:
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
startFormTopmostComonent |
boolean |
<optional> |
false
|
从最顶层的控件开始布局 |
enable()
- Description:
启用控件
- Inherited From:
expand()
- Description:
展开面板(与
collapse对应)
- Inherited From:
expandNode(node, deepopt)
- Description:
展开节点
Examples
展开单个节点:
FineUI.ui.tree1.expandNode('henan');
递归展开节点及其全部后代:
FineUI.ui.tree1.expandNode('henan', true);
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
||
deep |
boolean |
<optional> |
false
|
是否递归调用子节点 |
expandNodePath(node)
- Description:
展开节点所在路径
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
expandNodes()
- Description:
展开全部节点
expandPath(path)
- Description:
展开路径(沿路径上的祖先节点逐级展开,直到指定路径末端可见;通常配合
getNodePath取到目标节点的路径再调用)
Examples
通过节点 ID 拿到完整路径再展开:
var tree = FineUI.ui.tree1;
var path = tree.getNodePath('luohe'); // 例如:'fnode1/fnode3/luohe'
tree.expandPath(path);
等价的快捷方式(直接传节点而不是路径,框架内部会取路径再展开):
FineUI.ui.tree1.expandNodePath('luohe');
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | 节点路径(形如 |
getAttr(key) → {string}
- Description:
获取节点属性
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | 节点属性键 |
Returns:
节点属性值
- Type
- string
getCheckedNodes(returnNodeDataopt) → {Array.<string>|Array.<Object>}
- Description:
获取复选框处于选中状态的节点(不含
indeterminate半选中状态——半选中走getIndeterminateNodes)
Examples
仅取勾选节点的 ID 数组(用于序列化后提交服务端):
var ids = FineUI.ui.tree1.getCheckedNodes();
// 例如:['zhumadian', 'luohe']
取节点完整数据(含 text/iconFont 等):
var nodes = FineUI.ui.tree1.getCheckedNodes(true);
// 例如:[{ id: 'zhumadian', text: '驻马店' }, { id: 'luohe', text: '漯河' }]
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
returnNodeData |
boolean |
<optional> |
传 |
Returns:
节点标识符数组,或节点对象数组(取决于returnNodeData)
- Type
- Array.<string> | Array.<Object>
getEncodedText(text) → {string}
- Description:
获取编码后的字符串
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
text |
string | 原始字符串 |
Returns:
编码后的字符串
- Type
- string
getExpandedNodes() → {Array.<string>}
- Description:
获取展开的节点标识符数组
Returns:
节点标识符数组
- Type
- Array.<string>
getFormFields()
- Description:
不支持此方法
- Overrides:
getHeight() → {number}
- Description:
获取控件高度
- Inherited From:
Returns:
高度
- Type
- number
getIFrameEl() → {jQuery}
- Description:
获取内联框架元素
- Inherited From:
Returns:
内联框架元素
- Type
- jQuery
getIFrameUrl() → {string}
- Description:
获取内联框架地址
- Inherited From:
Returns:
内联框架地址
- Type
- string
getIFrameWindow() → {Window}
- Description:
获取内联框架窗体对象
- Inherited From:
Returns:
内联框架窗体对象
- Type
- Window
getIconEl() → {jQuery}
- Description:
获取图标元素
- Inherited From:
Returns:
图标元素
- Type
- jQuery
getIndeterminateNodes(returnNodeData) → {Array.<Object>}
- Description:
获取复选框处于中间状态的节点
Parameters:
| Name | Type | Description |
|---|---|---|
returnNodeData |
boolean | 返回包含节点对象的数组,否则返回包含节点标识符的数组 |
Returns:
节点数组
- Type
- Array.<Object>
getItem(value) → {FineUI.Component}
- Description:
获取子控件(按索引/标识符/匹配函数查找;通常配合
items无显式 id 的场景,比按FineUI.ui[id]更精准)
- Inherited From:
Examples
按索引取第一个子控件:
var firstChild = FineUI.ui.toolbar1.getItem(0);
按 id 取子控件:
var btn = FineUI.ui.toolbar1.getItem('btnSave');
按匹配函数找第一个匹配的子控件(函数对每项返回 true 即匹配):
var btn = FineUI.ui.toolbar1.getItem(function (item) {
return item.type === 'Button' && item.text === '保存';
});
Parameters:
| Name | Type | Description |
|---|---|---|
value |
number | string | function | 子控件索引、标识符或者匹配函数 |
Returns:
子控件实例
- Type
- FineUI.Component
getNodeCount(onlyLeafNode) → {number}
- Description:
获取节点个数
Parameters:
| Name | Type | Description |
|---|---|---|
onlyLeafNode |
boolean | 仅包含叶子节点 |
Returns:
节点个数
- Type
- number
getNodeData(node) → {Object}
- Description:
获取节点数据(返回节点的完整数据对象:含 id/text/iconFont/expanded/leaf/children 等)
Example
在nodeclick事件中取节点完整数据:
FineUI.create({
type: 'Tree',
listeners: {
nodeclick: function (event, nodeId) {
var node = this.getNodeData(nodeId);
// node 形如:{ id: 'luohe', text: '漯河', leaf: true, iconFont: '...' }
FineUI.alert('点击:' + node.text);
}
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
节点数据
- Type
- Object
getNodeEl(node) → {jQuery}
- Description:
获取节点元素
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
节点元素
- Type
- jQuery
getNodeId(node) → {string}
- Description:
获取节点标识符
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
节点标识符
- Type
- string
getNodePath(node) → {string}
- Description:
获取节点路径
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
节点路径
- Type
- string
getParentData(node) → {Object}
- Description:
获取父节点数据
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
父节点数据
- Type
- Object
getParentEl(node) → {jQuery}
- Description:
获取父节点元素
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
父节点元素
- Type
- jQuery
getParentId(node) → {string}
- Description:
获取父节点标识符
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
Returns:
父节点标识符
- Type
- string
getRootNode() → {Object}
- Description:
获取根节点
Returns:
根节点
- Type
- Object
getScrollEl() → {jQuery}
- Description:
获取可滚动元素
- Inherited From:
Returns:
可滚动元素
- Type
- jQuery
getSelectedNode(returnNodeData) → {string}
- Description:
获取选中的第一个节点
Parameters:
| Name | Type | Description |
|---|---|---|
returnNodeData |
boolean | 返回节点对象,否则返回节点标识符 |
Returns:
选中的第一个节点标识符
- Type
- string
getSelectedNodes(returnNodeData) → {Array.<string>}
- Description:
获取选中的节点标识符数组
Parameters:
| Name | Type | Description |
|---|---|---|
returnNodeData |
boolean | 返回包含节点对象的数组,否则返回包含节点标识符的数组 |
Returns:
节点标识符数组
- Type
- Array.<string>
getTitle() → {string}
- Description:
获取面板标题
- Inherited From:
Returns:
标题文本
- Type
- string
getTitleTooltip() → {string}
- Description:
获取面板标题提示信息
- Inherited From:
Returns:
标题提示信息
- Type
- string
getTooltip() → {string}
- Description:
获取提示信息
- Inherited From:
Returns:
提示信息
- Type
- string
getWidth() → {number}
- Description:
获取控件宽度
- Inherited From:
Returns:
宽度
- Type
- number
hasHScrollbar() → {boolean}
- Description:
是否存在水平滚动条
- Inherited From:
Returns:
是否存在水平滚动条
- Type
- boolean
hasIcon() → {boolean}
- Description:
是否有图标
- Inherited From:
Returns:
是否有图标
- Type
- boolean
hasVScrollbar() → {boolean}
- Description:
是否存在垂直滚动条
- Inherited From:
Returns:
是否存在垂直滚动条
- Type
- boolean
hide()
- Description:
隐藏面板
- Inherited From:
hideIcons()
- Description:
隐藏节点图标
hideLoading()
- Description:
隐藏加载动画
- Inherited From:
hidePopEl()
- Description:
隐藏容器内的所有弹出框
- Inherited From:
insert(insertIndex, value)
- Description:
插入新的子控件到当前控件
- Inherited From:
Examples
向菜单的开头插入一个新菜单项和一个分隔符('-' 是 MenuSeparator 的快捷字符串形式):
// 假设 menu1 当前 items 为:[菜单1, 菜单2, 菜单3]
FineUI.ui.menu1.insert(0, [
{ type: 'MenuItem', text: '新增', iconFont: 'plus' },
'-'
]);
// 插入后 items 顺序:[新增, ----, 菜单1, 菜单2, 菜单3]
在工具栏第 2 项位置插入一个分隔符和一个新按钮(Toolbar 中的'-' 是 ToolbarSeparator 的快捷字符串形式):
FineUI.ui.toolbar1.insert(2, [
'-',
{ type: 'Button', text: '新增', iconFont: 'plus' }
]);
Parameters:
| Name | Type | Description |
|---|---|---|
insertIndex |
number | 插入的位置(从 0 开始;如果 ≥ 当前子项数量,则追加到末尾) |
value |
Object | Array.<Object> | 控件实例(或控件实例数组,一次插入多个,按数组顺序) |
insertTool(insertIndex, item)
- Description:
插入工具图标
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
insertIndex |
number | 插入的位置 |
item |
FineUI.Tool | 工具图标实例 |
isCollapsed() → {boolean}
- Description:
是否处于折叠状态
- Inherited From:
Returns:
折叠状态
- Type
- boolean
isDirty()
- Description:
不支持此方法
- Overrides:
isDisabled() → {boolean}
- Description:
是否禁用
- Inherited From:
Returns:
是否禁用
- Type
- boolean
isNodeSelected(nodeId) → {boolean}
- Description:
节点是否处于选中状态
Parameters:
| Name | Type | Description |
|---|---|---|
nodeId |
string | 节点标识符 |
Returns:
节点是否处于选中状态
- Type
- boolean
isType(value) → {boolean}
- Description:
检测当前实例是否指定的控件类型
- Inherited From:
Example
grid1.isType('panel') // 返回true
grid1.isType('grid') // 返回true
Parameters:
| Name | Type | Description |
|---|---|---|
value |
Object | 控件类型 |
Returns:
如果当前实例是指定的控件类型,返回true;否则返回false
- Type
- boolean
isValid()
- Description:
不支持此方法
- Overrides:
isVisible() → {boolean}
- Description:
是否可见
- Inherited From:
Returns:
是否可见
- Type
- boolean
loadData(parentNodeIdopt, data)
- Description:
重新加载数据
Examples
替换整棵树的根数据:
FineUI.ui.tree1.loadData([
{ id: 'a', text: '分类 A', children: [{ id: 'a1', text: 'A-1', leaf: true }] },
{ id: 'b', text: '分类 B', leaf: true }
]);
懒加载场景:响应nodelazyload事件加载某节点的子项:
FineUI.create({
type: 'Tree', autoLeafIdentification: false,
rootNode: { expanded: true, children: [{ id: 'henan', text: '河南' }] },
listeners: {
nodelazyload: function (event, nodeId) {
// 模拟 ajax 拉子节点数据
if (nodeId === 'henan') {
this.loadData(nodeId, [
{ id: 'zhengzhou', text: '郑州', leaf: true },
{ id: 'luohe', text: '漯河', leaf: true }
]);
}
}
}
});
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
parentNodeId |
string |
<optional> |
需要加载的父节点(如果不传入此参数,则表示更新根节点数据) |
data |
Array.<Object> | 节点数据 |
moveNode(node, targetNode, position) → {string}
- Description:
移动节点(用于拖拽排序或程序化重组树结构;
append表示作为目标节点的最后一个子节点,prepend作为第一个子节点)
Examples
将节点放到目标节点之后(同级排序):
FineUI.ui.tree1.moveNode('luohe', 'zhumadian', 'after');
将节点放到目标节点的子节点末尾(移动到新父节点下):
FineUI.ui.tree1.moveNode('luohe', 'henan', 'append');
Parameters:
| Name | Type | Description |
|---|---|---|
node |
string | jQuery | 需要移动的节点(节点标识符或者节点元素) |
targetNode |
string | jQuery | 目标节点(节点标识符或者节点元素) |
position |
string | 相对于目标节点的位置(可选项为:before, after, append, prepend) |
Returns:
节点路径
- Type
- string
off(eventNames, fnopt)
- Description:
移除事件
- Inherited From:
Examples
移除特定回调:
function onMyClick() { ... }
FineUI.ui.btn1.on('click', onMyClick);
// 后续解绑:
FineUI.ui.btn1.off('click', onMyClick);
移除某事件下的全部回调(不传 fn 参数):
FineUI.ui.btn1.off('click');
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
eventNames |
string | 事件名称(可以空格分割多个事件名称) |
|
fn |
F_Component_on |
<optional> |
之前注册的事件处理函数(留空则移除该事件的所有回调) |
on(eventNames, fn)
- Description:
注册事件(运行时绑定;与配置参数
listeners的初始绑定等价,但可在控件创建后动态追加)
- Inherited From:
Examples
初始绑定形态:在FineUI.create时通过listeners配置项一次性声明:
FineUI.create({
type: 'Button', renderTo: document.body, text: '按钮',
listeners: {
click: function (event) {
FineUI.alert('button clicked');
},
// 同一个 listeners 内可以同时声明多个事件
beforeclick: function (event) {
// 返回 false 可阻止 click 事件
}
}
});
运行时绑定形态:控件创建后通过on()追加,效果与上面的listeners等价:
FineUI.ui.btn1.on('click', function (event) {
FineUI.alert('button clicked');
});
on()一次绑定多个事件(事件名之间空格分隔):
FineUI.ui.tbxName.on('focus blur', function () {
console.log('focus 或 blur 触发');
});
Parameters:
| Name | Type | Description |
|---|---|---|
eventNames |
string | 事件名称(可以空格分割多个事件名称) |
fn |
F_Component_on | 触发事件时执行的函数 |
refreshIFrame()
- Description:
刷新内联框架
- Inherited From:
remove()
- Description:
从父控件中移除当前控件并销毁其 DOM(不可恢复;移除后
FineUI.ui[id]也会清除)。触发remove事件可用于清理外部资源。
- Inherited From:
Example
动态添加 + 移除子控件:
var btn = FineUI.create({
type: 'Button', text: '临时按钮', renderTo: document.body
});
// 5 秒后移除
setTimeout(function () {
btn.remove();
}, 5000);
removeAttr(key)
- Description:
删除节点属性
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | 节点属性键 |
removeTooltip()
- Description:
删除提示信息
- Inherited From:
reset()
- Description:
不支持此方法
- Overrides:
resolveNode(fn, startNode)
- Description:
遍历节点
Parameters:
| Name | Type | Description |
|---|---|---|
fn |
F_Tree_resolveNode | 遍历节点的回调函数 |
startNode |
Object | 遍历开始节点 |
scrollToNode(node)
- Description:
滚动到节点
Parameters:
| Name | Type | Description |
|---|---|---|
node |
number | string | jQuery | 节点索引、节点标识符或者节点元素 |
selectNode(node, optionsopt)
- Description:
选中单个节点(单选场景;多选用
selectNodes)
Examples
程序选中节点:
FineUI.ui.tree1.selectNode('luohe');
选中但不滚动到该节点:
FineUI.ui.tree1.selectNode('luohe', { scrollTo: false });
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
|||||||||||||||||
options |
Object |
<optional> |
参数 Properties
|
selectNodes(nodeIds, optionsopt)
- Description:
选中多个节点(多选场景
multiSelect: true时常用)
Examples
程序选中指定节点(替换当前选中):
FineUI.ui.tree1.selectNodes(['golden', 'ustc']);
在已有选中基础上追加(keep: true,对应 Ctrl+点击的效果):
FineUI.ui.tree1.selectNodes(['golden', 'ustc'], { keep: true });
Parameters:
| Name | Type | Attributes | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
nodeIds |
Array.<string> | 节点标识符数组 |
|||||||||||||||||
options |
Object |
<optional> |
参数 Properties
|
setAttr(key, value)
- Description:
设置节点属性
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
key |
string | 节点属性键 |
value |
string | 节点属性值 |
setAttrs(attrs)
- Description:
设置节点属性
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
attrs |
Object | 节点属性对象 |
setDisabled(disabled)
- Description:
设置控件的禁用状态
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
disabled |
boolean | 是否禁用 |
setEnabled(enabled)
- Description:
设置控件的启用状态
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
enabled |
boolean | 是否启用 |
setHeight(height)
- Description:
设置控件高度
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
height |
number | 高度 |
setHidden(hidden)
- Description:
设置控件的隐藏状态
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
hidden |
boolean | 是否隐藏 |
setIFrameUrl(url)
- Description:
设置内联框架地址
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | 内联框架地址 |
setIcon(icon)
- Description:
设置图标地址
- Inherited From:
Example
FineUI.ui.panel1.setIcon('../res/images/16/1.png');
Parameters:
| Name | Type | Description |
|---|---|---|
icon |
string | 图标地址 |
setIconFont(iconFont)
- Description:
设置图标字体
- Inherited From:
Example
FineUI.ui.panel1.setIconFont('bank');
Parameters:
| Name | Type | Description |
|---|---|---|
iconFont |
string | 图标字体 |
setNodeText(nodeId, newText)
- Description:
设置节点文本(重命名节点)
Example
重命名节点:
FineUI.ui.tree1.setNodeText('henan', '河南省');
Parameters:
| Name | Type | Description |
|---|---|---|
nodeId |
string | 树节点标识符 |
newText |
string | 节点文本 |
setRootNode(rootNode)
- Description:
设置根节点(替换整棵树,包括根节点本身的配置;与
loadData(data)区别:loadData只替换子节点数据,本方法可同时改根节点属性如expanded)
Example
整棵树切换数据源:
FineUI.ui.tree1.setRootNode({
expanded: true,
children: [
{ id: 'a', text: '分类 A', children: [{ id: 'a1', text: 'A-1', leaf: true }] },
{ id: 'b', text: '分类 B', leaf: true }
]
});
Parameters:
| Name | Type | Description |
|---|---|---|
rootNode |
Object | 根节点 |
setSize(width, height)
- Description:
设置控件尺寸(同时设置宽高;等价于
setWidth + setHeight但只触发一次布局)
- Inherited From:
Example
响应窗口 resize 调整面板尺寸:
$(window).on('resize', function () {
FineUI.ui.panel1.setSize($(window).width() - 20, $(window).height() - 40);
});
Parameters:
| Name | Type | Description |
|---|---|---|
width |
number | 宽度 |
height |
number | 高度 |
setSplitDraggable() → {boolean}
- Description:
设置分隔条是否可以拖动
- Inherited From:
Returns:
是否可以拖动
- Type
- boolean
setTitle(title)
- Description:
设置面板标题(运行时更新标题栏文字;Window/Tab/Panel/Grid 等都支持)
- Inherited From:
Example
根据当前选中数据动态更新窗体标题:
FineUI.ui.grid1.on('rowclick', function (event, rowId) {
var row = this.getRowData(rowId);
FineUI.ui.window1.setTitle('详情:' + row.Name);
FineUI.ui.window1.show();
});
Parameters:
| Name | Type | Description |
|---|---|---|
title |
string | 标题文本 |
setTitleTooltip(tooltip)
- Description:
设置面板标题提示信息
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
tooltip |
string | 提示信息字符串 |
setTooltip(tooltip)
- Description:
设置提示信息
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
tooltip |
string | 提示信息 |
setVisible(visible)
- Description:
设置控件的显示状态
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
visible |
boolean | 是否可见 |
setWidth(width)
- Description:
设置控件宽度
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
width |
number | 宽度 |
show()
- Description:
显示控件(与
hide对应)
- Inherited From:
Example
根据下拉列表的选中项,联动显示某区块:
FineUI.ui.ddlType.on('change', function () {
if (this.getValue() === 'advanced') {
FineUI.ui.pnlAdvanced.show();
} else {
FineUI.ui.pnlAdvanced.hide();
}
});
showIcons()
- Description:
显示节点图标
showLoading(opacity, container)
- Description:
显示加载动画
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
opacity |
number | 透明度(默认值:0.65) |
container |
jQuery | 显示动画的目标元素(留空则为内容元素) |
toggleCollapse()
- Description:
切换面板的折叠状态
- Inherited From:
toggleEnabled()
- Description:
切换启用状态
- Inherited From:
toggleIcons()
- Description:
显示/隐藏节点图标
toggleVisible()
- Description:
切换显示状态
- Inherited From:
trigger(eventName, args)
- Description:
触发事件
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
eventName |
string | 事件名称 |
args |
Object | 事件参数 |
uncheckNode(node, options)
- Description:
取消选中节点复选框
Parameters:
| Name | Type | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
node |
string | jQuery | 节点标识符或者节点元素 |
||||||||
options |
Object | 参数 Properties
|
uncheckNodes(nodes, optionsopt)
- Description:
取消选中节点复选框(与
checkNodes对应)
Examples
批量取消勾选:
FineUI.ui.tree1.uncheckNodes(['zhumadian', 'luohe']);
取消勾选并递归子节点(清空某分支):
FineUI.ui.tree1.uncheckNodes(['henan'], { deep: true });
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
nodes |
Array.<string> | 节点标识符数组 |
|||||||||
options |
Object |
<optional> |
参数 Properties
|
Events
beforehide
- Description:
隐藏控件之前触发(返回false则取消隐藏操作)
- Inherited From:
beforeitemclick
- Description:
点击列表项之前触发(返回false则不执行FineUI.DataList#event:itemclick事件)
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
itemValue |
string | 列表项的值 |
beforenodeclick
- Description:
点击树节点之前触发(返回
false则阻止选中并取消nodeclick事件;典型场景:未保存修改时阻止切换节点)
Example
有未保存修改时弹确认框阻止切换:
FineUI.create({
type: 'Tree',
listeners: {
beforenodeclick: function (event, nodeId) {
if (FineUI.ui.form1.isDirty()) {
FineUI.alert('请先保存或撤销表单修改');
return false;
}
}
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
beforenodecontextmenu
- Description:
右键点击树节点时触发(返回false则阻止浏览器默认的右键菜单)
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
beforeshow
- Description:
显示控件之前触发(返回false则取消显示操作)
- Inherited From:
collapse
- Description:
折叠面板时触发(启用
collapsible: true时;用户点击折叠图标或调用collapse()都会触发)
- Inherited From:
Example
侧栏折叠后让中央面板"伸开"覆盖空间:
FineUI.ui.panelSide.on('collapse', function () {
FineUI.ui.panelMain.setWidth(window.innerWidth);
});
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
dataload
- Description:
树控件数据加载完毕时触发
dirtychange
- Description:
容器内的字段值改变时触发
- Inherited From:
expand
- Description:
展开面板时触发(与
collapse事件对应)
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
hide
- Description:
隐藏控件时触发
- Inherited From:
iframeload
- Description:
内联框架加载完毕时触发(启用
iframe: true时;常用于和 iframe 内部脚本通讯)
- Inherited From:
Example
iframe 加载完成后给子页面注入参数:
FineUI.create({
type: 'Window', iframe: true, iframeUrl: '/detail.aspx',
listeners: {
iframeload: function () {
var iframeWin = this.getIFrameWindow();
iframeWin.someInitFunction({ userId: 101 });
}
}
});
layout
- Description:
布局控件时触发
- Inherited From:
nodecheck
- Description:
选中/取消选中树节点复选框时触发(启用
checkbox: true时;若同时启用cascadeCheck,级联引发的兄弟/子节点变更也会逐个触发本事件)
Example
响应复选框变化,统计当前选中数量:
FineUI.create({
type: 'Tree', renderTo: document.body, height: 300, checkbox: true, cascadeCheck: true,
rootNode: {
expanded: true,
children: [
{ text: '河南省', expanded: true, children: [
{ id: 'zhumadian', text: '驻马店', leaf: true },
{ id: 'luohe', text: '漯河', leaf: true }
]}
]
},
listeners: {
nodecheck: function (event, nodeId, checked) {
// checked 为 true 表示刚被勾选;false 表示刚取消勾选
var count = this.getCheckedNodes().length;
FineUI.alert((checked ? '选中' : '取消') + ' ' + nodeId + ',当前共选中 ' + count + ' 项');
}
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
checked |
boolean | 树节点复选框的选中状态 |
nodeclick
- Description:
点击树节点时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
nodecollapse
- Description:
折叠树节点时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
nodedblclick
- Description:
双击树节点时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
nodedeselect
- Description:
取消选中节点时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 节点标识符 |
nodeexpand
- Description:
展开树节点时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
nodelazyload
- Description:
延迟加载树节点时触发(节点首次展开时触发;用户在事件回调里通过
loadData(nodeId, children)提供子节点数据)
Example
典型的懒加载实现(与autoLeafIdentification: false配合,让非叶子节点保留展开图标):
FineUI.create({
type: 'Tree', autoLeafIdentification: false,
rootNode: { expanded: true, children: [{ id: 'henan', text: '河南' }] },
listeners: {
nodelazyload: function (event, nodeId) {
// 实际项目这里通常发起 ajax 请求
var children = fetchChildrenFromServer(nodeId);
this.loadData(nodeId, children);
}
}
});
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
nodeselect
- Description:
选中树节点时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
nodeId |
string | 树节点标识符 |
remove
- Description:
移除控件时触发(调用
remove()时,控件 DOM 被销毁之前触发;可用于清理外部资源 / 解绑全局事件)
- Inherited From:
render
- Description:
渲染控件时触发
- Inherited From:
resize
- Description:
面板尺寸改变时触发
- Inherited From:
selectionchange
- Description:
选中的树节点改变时触发
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |
show
- Description:
显示控件时触发
- Inherited From:
splitdrag
- Description:
拖动分隔条时触发(拖动操作)
- Inherited From:
Parameters:
| Name | Type | Description |
|---|---|---|
event |
jQuery.Event | 事件对象 |