问题描述
{header: "密码", sortable:true, dataIndex:"card_password",renderer:function(value){return "<span style='color:#000000;'>"+value+"</span>"}},{header: "创建者", sortable:true,width: 60, dataIndex:"card_admin",renderer:function(value){return "<span style='color:#000000;'>"+value+"</span>"}},我的密码要根据创建者来显示,有些创建者密码要隐藏,这个功能要怎么做啊? 问题补充:大哥问下你这些要在哪里查啊?我下载的中文API没有这些啊。只能查到renderer : Function (可选的)该函数用于加工单元格的原始数据,转换成为HTML并返回给Gr... (可选的)该函数用于加工单元格的原始数据,转换成为HTML并返回给GridView进一步处理。请参阅setRenderer。如不指定,则对原始数据值进行默认地渲染。(optional) A function used to generate HTML markup for a cell given the cell's data value. See setRenderer. If not specified, the default renderer uses the raw data value.
解决方案
renderer:function(value, cellMeta, record, rowIndex, columnIndex, store){ // 得到创建者信息 var creator = record.data['card_admin']; // 是否显示密码(boolean) var isShowPassword = 自己的逻辑判断(creator); return "<span style='color:#000000;'>"+isShowPassword ? value : ''+"</span>"}} // value: 当前的值// cellMeta: 单元格式ID// record: 当前行的所有数据// rowIndex: 当前行的行号(分页后的)// columnIndex: 列号// store: 数据集
解决方案二:
renderer有6个参数:引用* value : ObjectThe data value for the cell.* metadata : ObjectAn object in which you may set the following attributes: o css : String A CSS class name to add to the cell's TD element. o attr : String An HTML attribute definition string to apply to the data container element within the table cell (e.g. 'style="color:red;"').* record : Ext.data.recordThe Ext.data.Record from which the data was extracted.* rowIndex : NumberRow index* colIndex : NumberColumn index* store : Ext.data.StoreThe Ext.data.Store object from which the Record was extracted.第3个参数就是record,用record.get(fieldName)来取其它列的值。例:record.get("card_admin")