多级菜单 Menu
示例
基本形式
<menu source={source} />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: '选项1', children: [
{name: '选项1.1'},
{name: '选项1.2', children: [
{name: '选项1.2.1'},
{name: '选项1.2.2'}
]},
{name: '选项1.3'},
{name: '选项1.4'},
]},
{name: '选项2'},
{name: '选项3', children: [
{name: '选项3.1'},
{name: '选项3.2'}
]}
]
}
});
修改标题
<menu source={source} title="修改标题" />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: '选项1', children: [
{name: '选项1.1'},
{name: '选项1.2', children: [
{name: '选项1.2.1'},
{name: '选项1.2.2'}
]},
{name: '选项1.3'},
{name: '选项1.4'},
]},
{name: '选项2'},
{name: '选项3', children: [
{name: '选项3.1'},
{name: '选项3.2'}
]}
]
}
});
禁用某一项,禁用组件
<menu source={source} />
<menu source={source} disabled />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: '选项1', children: [
{name: '选项1.1'},
{name: '选项1.2', children: [
{name: '选项1.2.1'},
{name: '选项1.2.2'}
]},
{name: '选项1.3'},
{name: '选项1.4'},
]},
{name: '选项2'},
{name: '选项3(禁用)', disabled: true, children: [
{name: '选项3.1'},
{name: '选项3.2'}
]}
]
}
});
分隔线
<menu source={source} />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: '选项1', children: [
{name: '选项1.1'},
{divider: true},
{name: '选项1.2', children: [
{name: '选项1.2.1'},
{name: '选项1.2.2'}
]},
{name: '选项1.3'},
{name: '选项1.4'},
]},
{name: '选项2'},
{divider: true},
{name: '选项3(禁用)', disabled: true, children: [
{name: '选项3.1'},
{name: '选项3.2'}
]}
]
}
});
按钮自定义
<menu source={source}>
<a class="u-btn u-btn-primary">Primary</a>
</menu>
<menu source={source}>
<a class="u-btn u-btn-success">Success</a>
</menu>
<menu source={source}>
<a class="u-btn u-btn-warning">Warning</a>
</menu>
<menu source={source}>
<a class="u-btn u-btn-error">Error</a>
</menu>
<menu source={source}>
<a>Link</a>
</menu>
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: '选项1', children: [
{name: '选项1.1'},
{name: '选项1.2', children: [
{name: '选项1.2.1'},
{name: '选项1.2.2'}
]},
{name: '选项1.3'},
{name: '选项1.4'},
]},
{name: '选项2'},
{name: '选项3', children: [
{name: '选项3.1'},
{name: '选项3.2'}
]}
]
}
});
单项模板自定义
<menu source={source} itemTemplate={@(itemTemplate)} />
var component = new RGUI.Component({
template: template,
itemTemplate: RGUI._.multiline(function(){/*
<a href={item.url}>{item.name}</a>
*/}),
data: {
source: [
{name: '首页', url: '../index.html'},
{name: 'CSS元件', url: '../cssunit/index.html', children: [
{name: '基础', url: '../cssunit/base.html'},
{name: '按钮', url: '../cssunit/button.html'},
{name: '图标', url: '../cssunit/icon.html'}
]},
{name: 'JS元件', url: 'index.html', children: [
{name: 'Dropdown', url: 'dropdown.html'},
{name: 'Menu', url: 'menu.html'},
{name: 'Input2', url: 'input2.html'}
]}
]
}
});
API
Class
Menu
继承自Dropdown。
Options
new Menu()
参数 | 类型 | 默认值 | 数据流向 | 描述 |
---|---|---|---|---|
data | object | 绑定属性 | ||
data.title | string | '' | outer => inner | 按钮文字 |
data.source | object[] | [] | outer <=> inner | 数据源 |
data.source[].name | string | outer => inner | 每项的内容 | |
data.source[].disabled | boolean | false | outer => inner | 禁用此项 |
data.source[].divider | boolean | false | outer => inner | 设置此项为分隔线 |
data.itemTemplate | string | null | outer @=> inner | 单项模板 |
data.open | boolean | false | outer <=> inner | 当前为展开/收起状态 |
data.disabled | boolean | false | outer => inner | 是否禁用 |
data.visible | boolean | true | outer => inner | 是否显示 |
data.class | string | '' | outer => inner | 补充class |
service | object | outer @=> inner | 数据服务 |
Inherited Methods
menu.toggle(open)
展开/收起
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
open | boolean | 展开/收起状态。如果无此参数,则在两种状态之间切换。 | |
返回值 | 类型 | 描述 | |
无返回值 |
menu.select(item)
选择某一项
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
item | object | 选择项 | |
返回值 | 类型 | 描述 | |
无返回值 |
@deprecated menu.$updateSource()
从service中更新数据源
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
无参数 | |||
返回值 | 类型 | 描述 | |
this | SourceComponent |
Inherited Events
menu.$on('toggle')
展开/收起时触发
属性 | 类型 | 描述 |
---|---|---|
sender | object | 事件发送对象 |
open | object | 展开/收起状态 |
menu.$on('select')
选择某一项时触发
属性 | 类型 | 描述 |
---|---|---|
sender | object | 事件发送对象 |
selected | object | 当前选择项 |