日期:2014-05-16  浏览次数:20784 次

新手问:ext4 livegrid中checkbox如何获取值 - Web 开发 / Ajax
使用它的http://dev.sencha.com/deploy/ext-4.0.2a/examples/grid/infinite-scroll.html例子加checkbox后如何取值和赋值?
JScript code

Ext.Loader.setConfig({enabled: true});

Ext.Loader.setPath('Ext.ux', 'js/ext-4.0.0/examples/ux/');
Ext.require([
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.grid.PagingScroller',
    'Ext.ux.RowExpander',
    'Ext.selection.CheckboxModel'
    
]);

var rec = "";

Ext.onReady(function(){
    Ext.define('ForumThread', {
        extend: 'Ext.data.Model',
        fields: [
            'title', 'forumtitle', 'forumid', 'author',
            {name: 'replycount', type: 'int'},
            {name: 'lastpost', mapping: 'lastpost', type: 'date', dateFormat: 'timestamp'},
            'lastposter', 'excerpt', 'threadid'
        ],
        idProperty: 'threadid'
    });

    // create the Data Store
     //var sm = Ext.create('Ext.selection.CheckboxModel');
    
    var store = Ext.create('Ext.data.Store', {
        id: 'store',
        pageSize: 200,
        model: 'ForumThread',
        remoteSort: true,
        buffered: true,
        proxy: {
            type: 'jsonp',
            url: 'http://www.sencha.com/forum/remote_topics/index.php',
            extraParams: {
                total: 50000
            },
            reader: {
                root: 'topics',
                totalProperty: 'totalCount'
            },
            simpleSortMode: true
        },
        sorters: [{
            property: 'lastpost',
            direction: 'DESC'
        }]
    });

    function renderTopic(value, p, record) {
        return Ext.String.format(
            '<a href="http://sencha.com/forum/showthread.php?t={2}" target="_blank">{0}</a>',
            value,
            record.data.forumtitle,
            record.getId(),
            record.data.forumid
        );
    }

    var sm = Ext.create('Ext.selection.CheckboxModel');
     
    var grid = Ext.create('Ext.grid.Panel', {
        width: 700,
        height: 500,
        id:'xxgrid',
        title: 'checkbox',
        store: store,
        selModel: sm,
        selModel : new Ext.selection.CheckboxModel({singleSelect : false}),
        frame: true,
        verticalScrollerType: 'paginggridscroller',
        loadMask: true,
        disableSelection: false,
        invalidateScrollerOnRefresh: false,
        viewConfig: {
        trackOver: false
        },
        // grid columns
        columns:[
        {
            id: 'topic',
            text: "Topic",
            dataIndex: 'title',
            flex: 1,
            renderer: renderTopic,
            sortable: false
        },{
            text: "Author",
            dataIndex: 'author',
            width: 100,
            hidden: true,
            sortable: true
        },{
            text: "Replies",
            dataIndex: 'replycount',
            align: 'center',
            width: 70,
            sortable: false
        },{
            id: 'last',
            text: "Last Post",
            dataIndex: 'lastpost',
            width: 130,
            renderer: Ext.util.Format.dateRenderer('n/j/Y g:i A'),
            sortable: true
        }],
        renderTo: 'grid-example'
    });

    
   // trigger the data store load
    store.guaranteeRange(0, 199);
    
});

    function chkVal(){
        var selChk;
        rec = Ext.getCmp('xxgrid').getSelectionModel().getSelection();
        //alert(rec.get['Replies']);
        for (var i = 0; i < rec.length; i++) {
            selChk += rec[i].get("last")
            if (i < rec.length - 1) {
                selChk = selChk + ",";
                }
        }
        alert(selChk);
        }
 



------解决方案--------------------