自动提示 Suggest
示例
基本形式
<suggest source={source} />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: 'abandon'},
{name: 'about'},
{name: 'absent'},
{name: 'bread'},
{name: 'break'},
{name: 'brief'},
{name: 'calendar'},
{name: 'cancel'},
{name: 'column'}
]
}
});
禁用某一项,禁用组件
<suggest source={source} />
<suggest source={source} disabled />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: 'abandon'},
{name: 'about'},
{name: 'absent(禁用)', disabled: true},
{name: 'bread'},
{name: 'break(禁用)', disabled: true},
{name: 'brief'},
{name: 'calendar'},
{name: 'cancel(禁用)', disabled: true},
{name: 'column'}
]
}
});
Placeholder
<suggest source={source} placeholder="输入时会自动提示" />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: 'abandon'},
{name: 'about'},
{name: 'absent'},
{name: 'bread'},
{name: 'break'},
{name: 'brief'},
{name: 'calendar'},
{name: 'cancel'},
{name: 'column'}
]
}
});
开始提示长度
当输入长度>=startLength
属性后开始提示。
<suggest source={source} placeholder="输入2个字符后开始提示" startLength="2" />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: 'abandon'},
{name: 'about'},
{name: 'absent'},
{name: 'bread'},
{name: 'break'},
{name: 'brief'},
{name: 'calendar'},
{name: 'cancel'},
{name: 'column'}
]
}
});
匹配方式
<suggest source={source} placeholder="匹配全局" matchType="all" />
<suggest source={source} placeholder="只匹配开头" matchType="start" />
<suggest source={source} placeholder="只匹配结尾" matchType="end" />
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: 'abandon'},
{name: 'about'},
{name: 'absent'},
{name: 'bread'},
{name: 'break'},
{name: 'brief'},
{name: 'calendar'},
{name: 'cancel'},
{name: 'column'}
]
}
});
严格模式
当为严格模式时,value
属性必须在source中选择,否则为空。
<p><suggest source={source} placeholder="非严格模式" value={value1} /> {value1}</p>
<p><suggest source={source} placeholder="严格模式" strict value={value2} /> {value2}</p>
var component = new RGUI.Component({
template: template,
data: {
source: [
{name: 'abandon'},
{name: 'about'},
{name: 'absent'},
{name: 'bread'},
{name: 'break'},
{name: 'brief'},
{name: 'calendar'},
{name: 'cancel'},
{name: 'column'}
]
}
});
远程数据
支持远程过滤。
<suggest service={@(this.service)} />
var component = new RGUI.Component({
template: template,
service: {
getList: function(params, success) {
RGUI.ajax.request({
url: '../data/suggest.json',
method: 'get',
type: 'json',
data: params,
success: success
});
}
}
});
API
Class
Suggest
继承自Dropdown。
Options
new Suggest()
参数 | 类型 | 默认值 | 数据流向 | 描述 |
---|---|---|---|---|
data | object | 绑定属性 | ||
data.source | object[] | [] | outer <=> inner | 数据源 |
data.source[].name | string | outer => inner | 每项的内容 | |
data.source[].disabled | boolean | false | outer => inner | 禁用此项 |
data.selected | object | null | outer <=> inner | 当前选择项 |
data.value | string | '' | outer <=> inner | 文本框中的值 |
data.placeholder | string | '请输入' | outer => inner | 文本框的占位文字 |
data.maxlength | number | outer => inner | 文本框的最大长度 | |
data.startLength | number | 0 | outer => inner | 开始提示长度。当输入长度>=该值后开始提示 |
data.matchType | string | 'all' | outer => inner | 匹配方式,`all`表示匹配全局,`start`表示只匹配开头,`end`表示只匹配结尾 |
data.strict | boolean | false | outer => inner | 是否为严格模式。当为严格模式时,`value`属性必须在source中选择,否则为空。 |
data.autofocus | boolean | false | outer => inner | 是否自动获得焦点 |
data.itemTemplate | string | null | outer @=> inner | 单项模板 |
data.open | boolean | false | outer <=> inner | 当前为展开/收起状态 |
data.readonly | 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 | 数据服务 |
Methods
suggest.select(item)
选择某一项
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
item | object | 选择项 | |
返回值 | 类型 | 描述 | |
无返回值 |
suggest.toggle(open)
展开/收起
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
open | boolean | 展开/收起状态。如果无此参数,则在两种状态之间切换。 | |
返回值 | 类型 | 描述 | |
无返回值 |
Inherited Methods
@override suggest.toggle(open)
@override suggest.select(item)
@deprecated suggest.$updateSource()
从service中更新数据源
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
无参数 | |||
返回值 | 类型 | 描述 | |
this | SourceComponent |
Events
suggest.$on('select')
选择某一项时触发
属性 | 类型 | 描述 |
---|---|---|
sender | object | 事件发送对象 |
selected | object | 当前选择项 |
suggest.$on('toggle')
展开/收起时触发
属性 | 类型 | 描述 |
---|---|---|
sender | object | 事件发送对象 |
open | object | 展开/收起状态 |