EasyUI datagrid获取选中行 某列的值(经format格式化之后的值)

Wanted__杰 2014-11-27 09:12:40

function initGrid(){
$('#tt').datagrid({
url:'${ctx}/message/getMessagePage',
idField : "id",
pagination:true,
rownumbers : true,
fitColumns : true,
collapsible : true,
autoRowHeight : true,
loadMsg : "数据加载中,请稍等...",
frozenColumns : [[{field : 'ck',checkbox : true}]],
columns:[[
{title:'消息标题', field:'title',width:50,align:'center'},
{title:'消息文本内容', field:'description',width:50,align:'center'},
{title:'图片URL', field:'url',width:50,align:'center'},
{title:'消息类型', field:'messageTypeId',width:50,align:'center',formatter: function(value,row,index){
if (row.messageType){return row.messageType.name;}
else {return value;}
}},
{title:'发布人', field:'publisher',width:50,align:'center'},
{title:'发布时间', field:'createDate',width:50,align:'center',formatter:function(value){
if(value)return $.formatDate(value);
}},
{title:'更新时间', field:'updateDate',width:50,align:'center',formatter:function(value){
if(value)return $.formatDate(value);
}}
]], onClickRow:function (rowData){
var chks = $('#tt').datagrid('getChecked');
if(null!=chks && chks.length==1){
msgTyp = chks[0].messageTypeId;//获取到当前行消息的类型(主动推送或客户端拉取)
alert(msgTyp );
//根据消息类型显示或隐藏推送按钮
/* if(type=='推送消息'){
$("#pushMessage").show();
}else{
$("#pushMessage").hide();
} */
};
},
});
}

${ctx}/message/getMessagePage 返回的数据

{
"total": 1,
"pageSize": 10,
"pageNumber": 1,
"rows": [
{
"id": 21,
"messageType": {
"id": 6,
"name": "通知消息",
"description": "充值信息通知",
"isDel": null,
"createDate": null,
"updateDate": null,
"reserved1": null,
"reserved2": null,
"page": null
},
"title": " 测试",
"publisher": "管理员C",
"description": "测试消息",
"url": null,
"sort": null,
"isDel": null,
"createDate": 1416922656000,
"updateDate": null,
"reserved1": null,
"reserved2": null,
"page": null
}
]
}

页面现状



目的:选中某行时, 通过消息类型 控制推送按钮的隐藏或显示
现状:通过 chks[0].messageTypeId 获取到的为undefined 其他没format的值能获取到,比如 chks[0].title 能得到“测试”
...全文
4974 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Veilphonll 2017-08-08
  • 打赏
  • 举报
回复
怎么获取field中的值啊?
Wanted__杰 2014-11-27
  • 打赏
  • 举报
回复
引用 1 楼 showbo 的回复:
自己看你的数据源,返回的数据源就没有messageTypeId键,和你添加不添加formatter没关系
原来是这样。。。晕死
Go 旅城通票 2014-11-27
  • 打赏
  • 举报
回复
自己看你的数据源,返回的数据源就没有messageTypeId键,和你添加不添加formatter没关系

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧