最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I get the id in Extjs checkcolumn? - Stack Overflow

programmeradmin4浏览0评论

Im tiro in Extjs.

That is my model:

Ext.define('CatModel', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
     fields: [{
        name: "name",
        convert: undefined
    }, {
        name: "id",
        convert: undefined
    }]
}); 

store:

var store = Ext.create('Ext.data.TreeStore', {
    model:'CatModel',
    root: {
        expanded: true
    },
    proxy: {
        type: 'ajax',
        reader: 'json',
        url: 'item_access.jsp?fullpage=true&show_cat=1'
    }
});

and treePanel:

var treePanel = Ext.create('Ext.tree.Panel', {
    id: 'tree-panel',
    title: 'Sample Layouts',
    region:'north',
    split: true,
    height: 560,
    minSize: 150,
    rootVisible: false,
    autoScroll: true,
    store: store,
    columns: [
        {
            xtype: 'treecolumn',
            text: 'name',
            flex: 2.5,
            sortable: true,
            dataIndex: 'name'
        },
        {
            text: 'id',//I want to get this id
            flex: 1,
            dataIndex: 'id',
            sortable: true
        }
        , {
            xtype: 'checkcolumn',
            text: 'Done',
            dataIndex: 'done',
            width: 55,
            stopSelection: false,
            menuDisabled: true,
            listeners:{
                checkchange:function(cc,ix,isChecked){
                    //alert(isChecked);
                    //I want to get this row id in here 
                }
            }
        }]
});

In checkchange function there are three parameter one unknown,two is index, and three is check status ...

So how can I get the the same row id where I check the checkbox??

Can I find that id number by checkbox row index??

Im tiro in Extjs.

That is my model:

Ext.define('CatModel', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
     fields: [{
        name: "name",
        convert: undefined
    }, {
        name: "id",
        convert: undefined
    }]
}); 

store:

var store = Ext.create('Ext.data.TreeStore', {
    model:'CatModel',
    root: {
        expanded: true
    },
    proxy: {
        type: 'ajax',
        reader: 'json',
        url: 'item_access.jsp?fullpage=true&show_cat=1'
    }
});

and treePanel:

var treePanel = Ext.create('Ext.tree.Panel', {
    id: 'tree-panel',
    title: 'Sample Layouts',
    region:'north',
    split: true,
    height: 560,
    minSize: 150,
    rootVisible: false,
    autoScroll: true,
    store: store,
    columns: [
        {
            xtype: 'treecolumn',
            text: 'name',
            flex: 2.5,
            sortable: true,
            dataIndex: 'name'
        },
        {
            text: 'id',//I want to get this id
            flex: 1,
            dataIndex: 'id',
            sortable: true
        }
        , {
            xtype: 'checkcolumn',
            text: 'Done',
            dataIndex: 'done',
            width: 55,
            stopSelection: false,
            menuDisabled: true,
            listeners:{
                checkchange:function(cc,ix,isChecked){
                    //alert(isChecked);
                    //I want to get this row id in here 
                }
            }
        }]
});

In checkchange function there are three parameter one unknown,two is index, and three is check status ...

So how can I get the the same row id where I check the checkbox??

Can I find that id number by checkbox row index??

Share Improve this question edited May 11, 2020 at 9:15 user11141611 asked Oct 16, 2013 at 8:02 chanjianyichanjianyi 6154 gold badges15 silver badges37 bronze badges 5
  • Can you explain what exactly you mean with "row id"? Usually a row is based on a record (i.e. an instance of the model), do you want that? – matt Commented Oct 16, 2013 at 8:39
  • docs.sencha./extjs/4.2.2/#!/api/… says the first parameter is The node who's checked property was changed. – Lorenz Meyer Commented Oct 16, 2013 at 8:39
  • The listener is on the column, so you need to refer to the event on Ext.grid.column.Check instead of the TreePanel – matt Commented Oct 16, 2013 at 8:46
  • @matt there are three coloums in my treePanel , 1 is treecolumn “name” , 2 is id , 3 is checkcolumn "done", when i click the "done" checkbox, I want to get the same row id.. – chanjianyi Commented Oct 16, 2013 at 8:58
  • @matt so in my example, there not possible to get that id? – chanjianyi Commented Oct 16, 2013 at 9:04
Add a ment  | 

1 Answer 1

Reset to default 8

You should be able to get the record from the TreeView with the row index, and then get the id property from it:

listeners:{
    checkchange: function(col, idx, isChecked) {
        var view = treePanel.getView(),
            record = view.getRecord(view.getNode(idx));

        console.log(record.get('id'));
    }
}
发布评论

评论列表(0)

  1. 暂无评论