PassUserPanel=Ext.extend(Michael.Ext.BasePanel,{
id:"passUserPanel",
title:"注册用户审核",
optionRender:function(obj)
{
if(obj)return "<a href='javascript:passUser("+obj+")'>通过审核</a>";
},
passUser:function(id){
window.alert(id);
},
storeMapping:["id","loginName","companyName","companyCity","busineScope",{name:"regDate",type:"date",dateFormat:"Y-n-j"},"busineType",{name:"op",mapping:"id"}],
initComponent:function(){
this.columeModel=new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{header:"编号",dataIndex:"id",hidden:true,sortable:true,width:60},
{header:"登录名",dataIndex:"loginName",width:80},
{header:"公司名称",dataIndex:"companyName",width:200,renderer:this.showtype},
{header:"所在城市",dataIndex:"companyCity",width:110},
{header:"业务类型",dataIndex:"busineType",width:150},
{header:"业务范围",dataIndex:"busineScope",width:300},
{header:"注册时间",sortable:true,dataIndex:"regDate",width:100,renderer:Ext.util.Format.dateRenderer("Y-m-d")},
{header:"操作",dataIndex:"op",sortable:false,width:60,renderer:this.optionRender} ]);
PassUserPanel.superclass.initComponent.call(this);
}
});定义了“操作”列 (红色代码部分)显示 “通过审核”点击改文字执行一段JS脚本(绿色部分),这段JS写在这里(蓝色部分)点击文字不会执行 提示 缺少对象。求解。
optionRender:function(obj)
{
var me = this;
if(obj)return "<a href='javascript:me.passUser("+obj+")'>通过审核</a>";
}, initComponent:function(){
var me = this;
this.columeModel=new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{header:"编号",dataIndex:"id",hidden:true,sortable:true,width:60},
{header:"登录名",dataIndex:"loginName",width:80},
{header:"公司名称",dataIndex:"companyName",width:200,renderer:this.showtype},
{header:"所在城市",dataIndex:"companyCity",width:110},
{header:"业务类型",dataIndex:"busineType",width:150},
{header:"业务范围",dataIndex:"busineScope",width:300},
{header:"注册时间",sortable:true,dataIndex:"regDate",width:100,renderer:Ext.util.Format.dateRenderer("Y-m-d")},
{header:"操作",dataIndex:"op",sortable:false,width:60,renderer:me.optionRender} ]);
PassUserPanel.superclass.initComponent.call(this);
}
if(obj)return "<a href='javascript:passUser("+obj+")'>通过审核</a>";这么写 是调不到这个passUser方法的 因为passUser是当前对象的方法 而不是全局的 这也正是缺少对象的原因
我给你改的那样 就可以调用到了为了避免这种this的指代问题 我们最好的办法就是将这个指代提出 作为一个局部变量 到哪也不会指错
optionRender: function(obj) {
var me = this;
if(obj) {
return "<a href='javascript:void(0)' id='aaa'>通过审核</a>";
//没用过ext,所以下面的没用框架写
document.getElementById('aaa').onclick = function() {
me.passUser(obj);
};
}
}
optionRender : function(obj) {
var me = this;
window.passUser = me.passUser;//必须要赋给window 否则下边无论如何都调不到 因为你是在标签里调用的
if (obj) {
//之前你的这个写的也有点问题 obj是个string 要加引号 否则就成了变量
return "<a href='javascript:passUser(\"" + obj + "\")'>通过审核</a>";//修改之后
}}