2010-08-10 100 views
0

我想创建一个使用ListView组件的复选框列表。以下是我的代码。如何使用Ext.ListView组件创建单选择复选框列表?

<script type="text/javascript"> 
Ext.onReady(function(){ 
    Ext.BLANK_IMAGE_URL = 'blank.gif'; 

    var genres = new Ext.data.SimpleStore({ 
    fields: ['id','genre'], 
    data: [['1','Comedy'],['4','Drama'],['3','Action']] 
    }); 
    var list1 = new Ext.list.ListView({ 
    store: genres, 
    width: 120, 
    hideHeaders: true, 
    selectedClass: 'x-list-selected', 
    multiSelect: false, 
    singleSelect: true, 
    columns: [{dataIndex:'id',tpl:'<input type="checkbox" id="{id}"></input>',width:.2},{dataIndex:'genre',tpl:'{genre}',width:.5}] 
    }); 
    var myPanel = new Ext.Panel({ 
    renderTo: Ext.get('div_formPanel'), 
    layout: 'hbox', 
    autoWidth: true, 
    autoHeight: true, 
    id: 'myP', 
    autoScroll: true, 
    items:[list1] 
    }); 
}); 
</script> 

正如你所看到的,我在我的ListView中设置了SingleSelect模式的复选框。问题是在singleSelect时,复选框不能保持状态。基本上我点击复选框,但它不检查。但是,当我尝试用单选按钮交换复选框时,单击按钮确实填充单选按钮。有人可以指出我做错了什么,或者我怎样才能达到预期的效果。

谢谢

回答

0

我想你可能会想要使用Ext.grid.CheckboxSelectionModel的Ext.grid.GridPanel,而不是把你的Ext.list.ListView一个Ext.Panel的内部,使复选框用模板。

下面是一个例子:Sencha Grid Plugins Examples

您也可以配置singleSelect您Ext.grid.CheckboxSelectionModel:真正得到你想要的效果。

相关问题