datagrid的columns属性支持对象的子属性(类似user.userName)的方法
2017-01-13 02:17
387 查看
由供应商类型 查询 类型名称, 涉及两个表的一对一查询
Mapper配置文件
SupplierMapper.xml
<mapper namespace="ndd.ssm1.dao.SupplierMapper" >
<resultMap id="supplierMap" type="ndd.ssm1.entity.Supplier" >
<id column="sup_id" property="supId" jdbcType="INTEGER" />
<result column="sup_name" property="supName" jdbcType="VARCHAR" />
<result column="sup_linkman" property="supLinkman" jdbcType="VARCHAR" />
<result column="sup_phone" property="supPhone" jdbcType="VARCHAR" />
<result column="sup_address" property="supAddress" jdbcType="VARCHAR" />
<result column="sup_remark" property="supRemark" jdbcType="VARCHAR" />
<result column="sup_pay" property="supPay" jdbcType="VARCHAR" />
<result column="sup_type" property="supType" jdbcType="VARCHAR" />
<collection property="supplierType" resultMap="ndd.ssm1.dao.SupplierTypeMapper.supTypetMap"/>
</resultMap>
</mapper>
SupplierTypeMapper.xml
<mapper namespace="ndd.ssm1.dao.SupplierTypeMapper" >
<resultMap id="supTypetMap" type="ndd.ssm1.entity.SupplierType" >
<id column="sup_type_id" property="supTypeId" jdbcType="INTEGER" />
<result column="sup_type_Name" property="supTypeName" jdbcType="VARCHAR" />
</resultMap>
</mapper>
list.jsp dataGrid
columns:[[
{checkbox:true},
{field:'supId',title:'供应商编号',width:100},
{field:'supName',title:'供应商姓名',width:100},
{field:'supLinkman',title:'联系人价格',width:100},
{field:'supPhone',title:'电话',width:100},
{field:'supAddress',title:'地址',width:100},
{field:'supRemark',title:'备注',width:100},
{field:'supPay',title:'期初应付',width:100},
{field:'supplierType',
formatter : function(value,row,index){
if (row.supplierType){
return row.supplierType.supTypeName;
} else {
return value;
}},
title:'供应商类型',width:100}
]]
说明: 我的后台传给前台datagrid的数据有total和rows,它们的格式如下:
即rows里面的每个对象都有supId、supplierType、supName等属性,而属性supplierType本是一个对象,里面有supTypeId、supTypename这几个属性。现在需要把supplierType里面的supTypename给显示出来,因为直接在field中这样写
fileld:"field:supplierType.supTypename',这样在前台是显示出不来这一列的,因为fileld的格式不支持点操作符的用法。所以应该用easyui的api中的datagrid自带的一个格式化函数formatter(),formatter的具体说明请查阅api
{field:'supplierType',
formatter : function(value,row,index){
if (row.supplierType){
return row.supplierType.supTypeName;
} else {
return value;
}},
title:'供应商类型',width:100}
]]
SupplierType .java 供应商类型 | Supplier .java 供应商 |
public class SupplierType { private Integer supTypeId; private String supTypeName; private Supplier supplier; Get ... Set ... } | public class Supplier { private Integer supId; //编号 private String supName;//供应商名称 private String supLinkman;//联系人 private String supPhone;//电话 private String supAddress;//地址 private String supRemark;//备注 private double supPay ; //期初应付 private String supType ;//类型 private SupplierType supplierType; Get ... Set ... } |
SupplierMapper.xml
<mapper namespace="ndd.ssm1.dao.SupplierMapper" >
<resultMap id="supplierMap" type="ndd.ssm1.entity.Supplier" >
<id column="sup_id" property="supId" jdbcType="INTEGER" />
<result column="sup_name" property="supName" jdbcType="VARCHAR" />
<result column="sup_linkman" property="supLinkman" jdbcType="VARCHAR" />
<result column="sup_phone" property="supPhone" jdbcType="VARCHAR" />
<result column="sup_address" property="supAddress" jdbcType="VARCHAR" />
<result column="sup_remark" property="supRemark" jdbcType="VARCHAR" />
<result column="sup_pay" property="supPay" jdbcType="VARCHAR" />
<result column="sup_type" property="supType" jdbcType="VARCHAR" />
<collection property="supplierType" resultMap="ndd.ssm1.dao.SupplierTypeMapper.supTypetMap"/>
</resultMap>
</mapper>
SupplierTypeMapper.xml
<mapper namespace="ndd.ssm1.dao.SupplierTypeMapper" >
<resultMap id="supTypetMap" type="ndd.ssm1.entity.SupplierType" >
<id column="sup_type_id" property="supTypeId" jdbcType="INTEGER" />
<result column="sup_type_Name" property="supTypeName" jdbcType="VARCHAR" />
</resultMap>
</mapper>
list.jsp dataGrid
columns:[[
{checkbox:true},
{field:'supId',title:'供应商编号',width:100},
{field:'supName',title:'供应商姓名',width:100},
{field:'supLinkman',title:'联系人价格',width:100},
{field:'supPhone',title:'电话',width:100},
{field:'supAddress',title:'地址',width:100},
{field:'supRemark',title:'备注',width:100},
{field:'supPay',title:'期初应付',width:100},
{field:'supplierType',
formatter : function(value,row,index){
if (row.supplierType){
return row.supplierType.supTypeName;
} else {
return value;
}},
title:'供应商类型',width:100}
]]
说明: 我的后台传给前台datagrid的数据有total和rows,它们的格式如下:
即rows里面的每个对象都有supId、supplierType、supName等属性,而属性supplierType本是一个对象,里面有supTypeId、supTypename这几个属性。现在需要把supplierType里面的supTypename给显示出来,因为直接在field中这样写
fileld:"field:supplierType.supTypename',这样在前台是显示出不来这一列的,因为fileld的格式不支持点操作符的用法。所以应该用easyui的api中的datagrid自带的一个格式化函数formatter(),formatter的具体说明请查阅api
{field:'supplierType',
formatter : function(value,row,index){
if (row.supplierType){
return row.supplierType.supTypeName;
} else {
return value;
}},
title:'供应商类型',width:100}
]]
相关文章推荐
- 让datagrid中的columns属性支持对象的子属性(类似user.userName)的方法
- form表单中name属性值为submit时,无法提交,出现"对象不支持此属性或方法"
- 解决对象不支持“getElementsByClassName”属性或方法 ie兼容性
- VBScript提交表单提示-对象不支持此属性或方法
- 关于IE7打开任何网页弹出[未处理的异常('对象不支持此属性或方法')发生在iexplorer.exe]错误调试框的解决办法
- extjs在IE报对象不支持此属性或方法
- 对象不支持此属性或方法
- 页面老报错: 对象不支持此属性或方法
- struts javascript不能提交 提示 对象不支持此属性或方法
- 解决document.form1.submit()对象不支持此属性或方法的办法
- Thin的DateChooser代码学习(关于js的函数参数为一个完整的函数以及“对象不支持此属性或方法”错误的解决)(原创,转载请声明)
- 在实践中磨练——ASP错误:"对象不支持此属性或方法: 'eof' "
- 关于submit() 对象不支持此属性或方法的解决方法
- 解决document.form1.submit()对象不支持此属性或方法的办法
- 表单提交中form.action,form.submit()问题 *** 对象不支持此属性或方法
- 关于submit() 对象不支持此属性或方法的解决方法
- 常见错误:JavaScript 提交form 的时候,Error:对象不支持此属性或方法
- dwr:报 missing callfack function 或者 “错误:对象不支持此属性或方法”
- form submit 错误 对象不支持此属性或方法
- 页面老报错: 对象不支持此属性或方法