当前位置:编程学习 > JAVA >>

新手求回答 EXTJS的grids获取一行属性失败 有代码

//预加载提高运行速度
Ext.require([ 
    'Ext.grid.*', 
    'Ext.data.*' 
]); 
Ext.onReady(function(){ 
//Ext.define在这里是定义一个类
    Ext.define('MyData',{ 
        extend: 'Ext.data.Model', 
        fields: [ 
            //第一个字段需要指定mapping,其他字段,可以省略掉。 
            {name:'UserName',mapping:'UserName'}, 
             'Sex', 
             'Age', 
             'XueHao', 
             'BanJi' 
        ] 
    }); 
     
    //创建数据源 
    var store = Ext.create('Ext.data.Store', { 
        model: 'MyData', 
        proxy: { 
           //异步获取数据,这里的URL可以改为任何动态页面,只要返回JSON数据即可 
            type: 'ajax', 
            url: 'javascript/mydata.json', 
             
            reader: { 
                type: 'json', 
                root: 'items' 
            } 
        }, 
        autoLoad: true 
    });  

     
    //创建Grid 
    var grid = Ext.create('Ext.grid.Panel',{ 
        store: store, //读取数据源
        columns: [ 
            {text: "姓名", width: 120, dataIndex: 'UserName', sortable: true}, 
            {text: "性别", flex: 1, dataIndex: 'Sex', sortable: false}, 
            {text: "年龄", width: 100, dataIndex: 'Age', sortable: true}, 
            {text: "学号", width: 100, dataIndex: 'XueHao', sortable: true}, 
            {text: "班级", width: 100, dataIndex: 'BanJi', sortable: true} 
        ], 
        autoHeight: true, 
        width:480, 
        x:20, 
        y:40, 
        title: 'ExtJS4 Grid示例', 
        renderTo: 'demo',
        //事件监听
        /**
        listeners : { 
            
            'celldblclick':function(grid, rowIndex, columnIndex,item,e){ 
              alert('ok');
      } 
    },*/
        //grid属性配置
        viewConfig: { 
         /**
         forceFit:true,//当行大小变化时始终填充满   
            enableRowBody:true,//可以用两行tr来表示一行数据   
            showPreview:true,//初始显示预览效果,这个是自定义的属性   
            getRowClass : function(record, rowIndex, p, store){//CSS class name to add to the row.获得一行的css样式  */
            stripeRows: true //实现隔行换色
        }
        
    });
    grid.on('celldblclick',function(grid,rowIndex,colIndex){
     alert(rowIndex);
     alert(grid.getStore().getAt(rowIndex));
        var rec = grid.getStore().getAt(rowIndex);
    alert("保存 "+rec.get('name'));
    });
    就是在这里 总是获取不到grid.getStore().getAt(rowIndex) 求解答
}); Ext JS --------------------编程问答-------------------- 楼主要问准要害啊,代码那么长,大家眼睛又不是编译器 --------------------编程问答-------------------- //应该这样写
grid.on('rowdblclick',function(grid,rowIndex.e){
   var record = grid.getSelectionModel().getSelected();
   if(record != null && record != '' ){
        //执行目标代码
   }else{
        //提示未选中信息
   }
}) --------------------编程问答-------------------- grid 中的监听属性去掉自己写的celldbclick  cell为列 row为行
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,