easyUI dategrid field 用formatter顯示子屬性,easyuiformatter

來源:互聯網
上載者:User

easyUI dategrid field 用formatter顯示子屬性,easyuiformatter

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都沒有顯示資料了。






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.