EasyUI 中 DataGrid 控件 列 如何绑定对象中的属性
2016-09-15 09:56
399 查看
EasyUI 中 DataGrid 控件 是我们经常用到的控件之一,
但是 DataGrid 控件 在绑定显示列时却不支持对象属性绑定。
模型如下:
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 是一个对象
<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>
function managerRoleFormat(val,row){
if(val) return val.roleName;
else return "";
}
function managerStatusFormat(val,row){
switch(val){
case 0: return '停用';
case 1: return '正常';
default: return '';
}
}
这样通过 EasyUI 给我们提供的 formatter 函数 我们就可以实现 对象属性的绑定.
但是 DataGrid 控件 在绑定显示列时却不支持对象属性绑定。
模型如下:
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 是一个对象
<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>
function managerRoleFormat(val,row){
if(val) return val.roleName;
else return "";
}
function managerStatusFormat(val,row){
switch(val){
case 0: return '停用';
case 1: return '正常';
default: return '';
}
}
这样通过 EasyUI 给我们提供的 formatter 函数 我们就可以实现 对象属性的绑定.
相关文章推荐
- EasyUI 中 DataGrid 控件 列 如何绑定对象中的属性
- easyUI中datagrid如何展示对象下属性的多个子属性
- 如何通过使用 VisualC # 绑定到 ArrayList 对象或结构的 DataGrid 控件
- easyui datagrid 绑定json对象属性的属性
- easyui datagrid如何解析 一个对象的子对象的多个属性
- easyui datagrid如何解析 一个对象的子对象的多个属性
- 如何绑定IList集合中对象的复合属性到DataGrid中。
- (转帖)关于easyui中的datagrid在加载数据时候报错:无法获取属性"Length"的值,对象为null或未定义
- 为什么silverlight的PasswordBox控件的password属性不可以绑定?该如何实现绑定?
- 如何在DataGrid中访问复合对象属性
- EasyUI Datagrid 列属性函数中如何获取当前列信息
- silverlight的Datagrid控件列绑定属性笔记
- SNF快速开发平台MVC-EasyUI3.9之-DataGrid表格控件如何增加右键菜单
- EasyUI - datagrid中单元格里编辑控件的单击事件如何获取当前行的index
- ASP.Net控件模板中根据绑定对象的属性控制元素隐现技巧
- easyui - datagrid 加载二级对象属性
- jquery如何给对象动态添加属性以及选择器、事件的绑定
- [WinForm]DataGridView如何绑定对象的复合属性
- ASP.Net控件模板中根据绑定对象的属性控制元素隐现技巧
- WPF 如何在后台进行控件属性的绑定MVVM