我有一个Java Enum类:
public enum NciTaskType
{
PndReviewWoli, // 0
OspPlanning, // 1
;
@Override
public String toString()
{
switch (this)
{
case PndReviewWoli:
return "Pnd Review Woli";
case OspPlanning:
return "Osp Planning";
default:
throw new AssertionError();
}
}
}
现在,如何从toString()
访问此javascript/jquery
方法?
我想显示"Pnd Review Woli"
而不是"PndReviewWoli"
Javascript代码阻止:
$(document).ready(function ()
{
$('#woliContainer').jtable({
//title: 'TT LIST',
messages: {
noDataAvailable: 'No Pending Work Orders available!'
},
paging: true, //Enable paging
pageSize: 10, //Set page size (default: 10)
sorting: true,
actions: {
listAction: "/Vela-web-client/nci/getWoliList.htm"
},
fields: {
taskType: {
title: 'Type',
width: '10%',
edit: false,
display: function (data) {
return data.record.taskType;
}
},
}
});
$('#woliContainer').jtable('load');
});
HTML代码阻止:
<div id="woliContainer"></div>
N.B:jtable有一个jquery脚本,这里不关心。
答案 0 :(得分:1)
最好将字符串描述符放在枚举构造函数中。
public enum NciTaskType {
PndReviewWoli("Pnd Review Woli"),
OspPlanning("Osp Planning"),;
private final String desc;
private NciTaskType(String desc) {
this.desc = desc;
}
@Override
public String toString() {
return desc;
}
}
如何在JavaScript中访问该名称在很大程度上取决于您的架构。