EasyUI 中 DataGrid 控件 列 如何绑定对象中的属性
2016-07-07 16:33
561 查看
EasyUI 中 DataGrid 控件 是我们经常用到的控件之一,
但是 DataGrid 控件 在绑定显示列时却不支持对象属性绑定。
模型如下:
Java代码
![](http://kk380446.iteye.com/images/icon_star.png)
public class Manager implements java.io.Serializable {
private Integer id;
private Role role;
private String loginName;
private String password;
private int status;
private Date lastDate;
private Date createAt;
private String remarks;
//省略 get and set
}
其中Role 是一个对象
Java代码
![](http://kk380446.iteye.com/images/icon_star.png)
<table id="manager_datagrid">
<thead>
<tr>
<th data-options="field:'loginName'">帐号</th>
<th data-options="field:'role',formatter:managerRoleFormat">所属岗位</th>
<th data-options="field:'createAt'">创建时间</th>
<th data-options="field:'lastDate'">最后登录时间</th>
<th data-options="field:'status',formatter:managerStatusFormat">状态</th>
<th data-options="field:'remarks'">备注</th>
</tr>
</thead>
</table>
Js代码
![](http://kk380446.iteye.com/images/icon_star.png)
function managerRoleFormat(val,row){
if(val) return val.roleName;
else return "";
}
Java代码
![](http://kk380446.iteye.com/images/icon_star.png)
function managerStatusFormat(val,row){
switch(val){
case 0: return '停用';
case 1: return '正常';
default: return '';
}
}
这样通过 EasyUI 给我们提供的 formatter 函数 我们就可以实现 对象属性的绑定.
但是 DataGrid 控件 在绑定显示列时却不支持对象属性绑定。
模型如下:
Java代码
![](http://kk380446.iteye.com/images/icon_star.png)
public class Manager implements java.io.Serializable {
private Integer id;
private Role role;
private String loginName;
private String password;
private int status;
private Date lastDate;
private Date createAt;
private String remarks;
//省略 get and set
}
其中Role 是一个对象
Java代码
![](http://kk380446.iteye.com/images/icon_star.png)
<table id="manager_datagrid">
<thead>
<tr>
<th data-options="field:'loginName'">帐号</th>
<th data-options="field:'role',formatter:managerRoleFormat">所属岗位</th>
<th data-options="field:'createAt'">创建时间</th>
<th data-options="field:'lastDate'">最后登录时间</th>
<th data-options="field:'status',formatter:managerStatusFormat">状态</th>
<th data-options="field:'remarks'">备注</th>
</tr>
</thead>
</table>
Js代码
![](http://kk380446.iteye.com/images/icon_star.png)
function managerRoleFormat(val,row){
if(val) return val.roleName;
else return "";
}
Java代码
![](http://kk380446.iteye.com/images/icon_star.png)
function managerStatusFormat(val,row){
switch(val){
case 0: return '停用';
case 1: return '正常';
default: return '';
}
}
这样通过 EasyUI 给我们提供的 formatter 函数 我们就可以实现 对象属性的绑定.
相关文章推荐
- 【UGUI】UGUI的事件监听
- gyp ERR! build error
- 内存泄漏-非UI线程使用View.post()方法
- 问题:sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- 关于The serializable class UsersServlet does not declare a static final serialVersionUID field of type
- Druid使用起步—在javaWeb项目中配置监控
- 学习easyUI 扩展的Editable DataGrid组件
- UIScrollView常用属性/常用代理方法总结
- Unable to satisfy the following requirements解决方案
- (OK) Add a second NIC for a libvirt guest - virsh
- 为什么说GUI是单线程化的
- Testng测试报告美化buid.xml配置
- 347. Top K Frequent Elements
- Codeforces Round #293 (Div. 2) -- E. Arthur and Questions (思路 + 贪心)
- UIView剖析之Draw、Size、Layout方法
- ios UITableview头部图片弹簧效果
- Android uevent监控 UEventObserver
- UIMenuController 实现过程,以及不为人知的一些坑
- Uva 540 - Team Queue
- UITextView富文本、插入图片