列表视图 ListView

示例

基本形式

<listView source={source} />
var component = new RGUI.Component({
    template: template,
    data: {
        source: [
            {name: '选项1'},
            {name: '选项2'},
            {name: '选项3'}
        ]
    }
});

禁用某一项,禁用组件

<div class="g-row">
    <div class="g-col g-col-6">
        <listView source={source} />
    </div>
    <div class="g-col g-col-6">
        <listView source={source} disabled />
    </div>
</div>
var component = new RGUI.Component({
    template: template,
    data: {
        source: [
            {name: '选项1'},
            {name: '选项2'},
            {name: '选项3(禁用)', disabled: true}
        ]
    }
});

分隔线

<listView source={source} />
var component = new RGUI.Component({
    template: template,
    data: {
        source: [
            {name: '选项1'},
            {name: '选项2'},
            {divider: true},
            {name: '选项3(禁用)', disabled: true}
        ]
    }
});

多选

<listView source={source} multiple />
var component = new RGUI.Component({
    template: template,
    data: {
        source: [
            {name: '选项1'},
            {name: '选项2'},
            {divider: true},
            {name: '选项3(禁用)', disabled: true},
            {name: '选项4'},
            {name: '选项5'}
        ]
    }
});

远程数据

<listView service={@(this.service)} />
var component = new RGUI.Component({
    template: template,
    service: {
        getList: function(params, success) {
            RGUI.ajax.request({
                url: '../data/list.json',
                method: 'get',
                type: 'json',
                data: params,
                success: success
            });
        }
    }
});

单项模板自定义

<listView source={source} itemTemplate={@(this.itemTemplate)} />
var component = new RGUI.Component({
    template: template,
    itemTemplate: RGUI._.multiline(function(){/*
<div>
    <span class="number">{item_index + 1}.</span>
    <span class="title">{item.name}</span>
    <span class="hits f-fr">{item.hits}</span>
</div>
    */}),
    data: {
        source: [
            {name: '精通Javascript开发', org: '前端Funs', hits: 42371},
            {name: 'Android深入浅出', org: 'Android学院', hits: 30645},
            {name: 'cocos2dx游戏开发教程', org: '鱼C课程', hits: 25112},
            {name: 'MySQL数据库', org: 'LAMP兄弟连', hits: 18089},
            {name: 'Arduino初级教程', org: '硬件社', hits: 16361}
        ]
    }
});

API

Class

ListView

继承自SourceComponent

Options

new ListView()

参数类型默认值数据流向描述
dataobject绑定属性
data.sourceobject[][]outer <=> inner数据源
data.source[].namestringouter => inner每项的内容
data.source[].disabledbooleanfalseouter => inner禁用此项
data.source[].dividerbooleanfalseouter => inner设置此项为分隔线
data.source[].selectedbooleanfalseouter => inner多选时此项是否选中
data.selectedobjectnullouter <=> inner当前选择项。多选时无效。
data.multiplebooleanfalseouter => inner是否可以多选
data.itemTemplatestringnullouter @=> inner单项模板
data.readonlybooleanfalseouter => inner是否只读
data.disabledbooleanfalseouter => inner是否禁用
data.visiblebooleantrueouter => inner是否显示
data.classstring''outer => inner补充class
serviceobjectouter @=> inner数据服务

Methods

listView.select(item)

选择某一项

参数类型默认值描述
itemobject选择项
返回值类型描述
无返回值

Inherited Methods

@deprecated listView.$updateSource()

从service中更新数据源

参数类型默认值描述
无参数
返回值类型描述
thisSourceComponent

Events

listView.$on('select')

选择某一项时触发

属性类型描述
senderobject事件发送对象
selectedobject当前选择项