今天发现以前用renderer:function(value, cellmeta, record, rowIndex, columnIndex, store) 方法中的record属性可以得到单元格的值 record.get("id");便可以得到单元格的id属性。
但是今天我这里name是String型的。值是可以出来的,但学以前那样会传参不行了, 搞一大半天没有搞好来。大家帮忙看下<%@ page language="java" import="java.util.*" contentType="text/html;"   pageEncoding="utf-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<jsp:include page="../common/head.jsp"/>

<html>
<!-- 123-->
<script type="text/javascript">
var sum;
var pageCount=10;//设置分页查条目数
var stuStore=new Ext.data.JsonStore({ 
                url:'<%=request.getContextPath()%>/ext/extGirdAction!findStuAll.action',
               autoLoad:true,  
               baseParams:{start:0,limit:pageCount},//传递到后台的参数 
                method:'POST',
                fields:["id","name","sex","age"],  //字段数据
                root:"rows",                         //从后台取得的数据 
                totalProperty:"total"                 //从后台取得的数据总量 
          }); 
      
      function gridPanel(){
       Ext.QuickTips.init();// 有助于当鼠标放在Ext自带的图标上时能够显示提示的功能
  var sm = new Ext.grid.CheckboxSelectionModel();// new一个复选框
          var column=new Ext.grid.ColumnModel([
           new Ext.grid.RowNumberer(),sm,
{header:"学号",dataIndex:"id",width:120,align:'center',sortable:true}, 
{header:"姓名",dataIndex:"name",width:120,align:'center',sortable:true},
{header:"性别",dataIndex:"sex",width:120,align:'center',sortable:true},
{header:"年龄",dataIndex:"age",width:120,align:'center',sortable:true},
{header:"操作",renderer:function(value, cellmeta, record, rowIndex, columnIndex, store){
//alert(record.get("name"));// 可以得到当前对象所有的值
var operation = '<a href="javascript:void(0)" onclick="javascript:studele('+record.get("name")+')">删除</a>';
       return operation;
},width:120,align:'center',sortable:true
  }
            ]);  
          var grid = new Ext.grid.GridPanel({ 
           id:"MenuGridPanel",
           store:stuStore,  //表格的数据集 
            renderTo:Ext.getBody(),  // 节点
           collapsible : true,//允许展开和收缩
          
title:"Hello world",  //标题
height:317,  //高度
width:660,  //宽度
cm:column,  //字段
sm:sm, //复选框多选,默认单选
autoExpandColumn:0, 
draggable:true,//激活面板的拖动
loadMask:true, 
frame:true, 
autoScroll:true, 
tbar:new Ext.PagingToolbar({ //bbar 设置工具栏在底部
pageSize:pageCount,    
store:stuStore,  
displayInfo: true,     
            displayMsg: '显示 {0}-{1}条记录,共 {2} 条',     
emptyMsg: "没有记录",
items:['',{},'-',
{enableToggle: true,
  text: '批量删除',
  cls: 'x-btn-text-icon details',icon:"../extjs/images/plugin.gif",
  toggleHandler: function(btn, pressed){
  var rows=Ext.getCmp("MenuGridPanel").getSelectionModel().getSelections(); //得到
 
   if(!(rows.length>=1)){   
      Ext.Msg.alert("提示消息","请至少选择一行数据然后才能够删除.");
      return false;                   
     }
 Ext.Msg.confirm("确认消息框","是否对选中行进行删除操作",function(btn,txt){
  if(btn=="no")
  return false;
  else{
  var ids = "";
   for(var i=0;i<rows.length;i++){
    ids += rows[i].json.id + ",";//获取批量删除所需要的ID 
    }
    Ext.Msg.alert("提示消息","你要删除行的ID:"+ids);//下面就可以用$ajxs 的方式来进行传参了
  }
 });
  }
}]
               })  
 }); 
      }   
         
function studele(a){
alert(a);
 Ext.Msg.alert('提示框','删除成功');
 stuStore.reload();//刷新数据
}

function selectStu(){
var stuName=document.getElementById("stu_id").value.replace(/[ ]/g,"");//取值并去除空格
 //分页条件参数  
stuStore.on('beforeload',function(){  
  Ext.apply(
  this.baseParams, {'student.name':stuName}
  );
  });
if(stuName==''){
stuStore.load();//刷新数据
}else{
stuStore.reload();//刷新当前数据
}
 
}

//程序入口
$(function(){
gridPanel();
 });
</script> <body>

<div >

<div>
<br/><br/><br/>
姓名:
<input type="text" id="stu_id" />
<input type="button" value="查询" onclick="selectStu();">
<!-- <table id="hello"></table>-->
</div>

</div> 
<br>

<br>
</body>
</html>

解决方案 »

  1.   

    Uncaught ReferenceError: 张三 is not defined   老是报这个,张三显示出来的值
      

  2.   

    终于搞出来了,唉真苦逼啊 做个记录
    var operation = '<a href="javascript:void(0)"onclick="javascript:studele('+record.get("name")+')">删除</a>';
    上面的改成这样就可以传字符串了
    var operation = '<a href="javascript:roadDele(\''+record.get("id")+'\')" >删除</a>';