easyUI dategrid field 用formatter显示子属性

dategrid:

<body class="easyui-layout"  data-options="fit:true,border:false">
	<table id="dg" class="easyui-datagrid" data-options="fit:true,border:false"
			url="book/listBookForUser"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="bookId" width="50">书ID</th>
				<th field="bookName" width="50">书名</th>
				<th field="bookType" width="50" formatter="formatBookType">书类型</th>
				<th field="author" width="50">作者</th>
				<th field="callNumber" width="50">索书号</th>
				<th field="iSBN" width="50">ISBN</th>
				<th field="publisher" width="50">出版社</th>
				<th field="publishYear" width="50">出版年份</th>
				<th field="series" width="50">系列</th>
				<th field="language" width="50">语言</th>
				<th field="price" width="50">价格</th>
				<th field="page" width="50">页数</th>
			</tr>
		</thead>
	</table>

这里,book和bookType是多对一的关系,后台返回的json中,bookType又是一个json对象,要获得bookType的bookTypeName,不能直接用bookType.bookTypeName .所以在field的bookType字段加上formatter 。


	function formatBookType(val,row,index){
		//alert(row.bookType);
		if(val==null){
			return "";
		}else
			return row.bookType.bookTypeName;
	} 

val是该字段的值,即bookType。row是行值。这里注意,要加一个if为空的判断,因为我有的书籍没有设置类型,这样的话就会找不到类型名,造成整个date都没有显示数据了。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值