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>

여기 서 북 타 입 과 북 타 입 은 다 대 일 관계 입 니 다. 배경 에서 돌아 오 는 제 이 슨 에서 북 타 입 은 제 이 슨 대상 입 니 다. 북 타 입의 북 타 입 Name 을 얻 으 려 면 북 타 입. 북 타 입 Name 을 직접 사용 할 수 없습니다. 그래서 field 의 북 타 입 필드 에 formatter 를 추가 합 니 다.
	function formatBookType(val,row,index){
		//alert(row.bookType);
		if(val==null){
			return "";
		}else
			return row.bookType.bookTypeName;
	} 

val 은 이 필드 의 값, 즉 bookType 입 니 다.row 는 줄 값 입 니 다.여기에 if 를 빈 판단 으로 추가 해 야 합 니 다. 제 가 가지 고 있 는 책 은 유형 을 설정 하지 않 았 기 때문에 유형 명 을 찾 지 못 해서 전체 date 에 데 이 터 를 표시 하지 않 습 니 다.

좋은 웹페이지 즐겨찾기