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 "";}elsereturn row.bookType.bookTypeName;} val是该字段的值,即bookType。row是行值。这里注意,要加一个if为空的判断,因为我有的书籍没有设置类型,这样的话就会找不到类型名,造成整个date都没有显示数据了。

效果只能是既费时又没有胜利,再聪慧的人也没法成学。

easyUI dategrid field 用formatter显示子属性

相关文章:

你感兴趣的文章:

标签云: