先給出返回的json數據。javascript
{ "total": "2", "rows": [ { "id": "1", "name": "張富銀", "xiuhao": "2014009012", "exttend": { "sid": "1", "tid": "1", "tel": "18580711609", "qq": "564968550", "email": "myfirtyou@qq.com", "sxdw": "重慶源代碼教育諮詢有限公司", "sxdw_add": "重慶市永川區", "jjlxrtel": "15922879092" } }, { "id": "4", "name": "測試學生姓名", "xiuhao": "2014009013", "exttend": { "sid": "4", "tid": "1", "tel": "1234567890", "qq": "12345", "email": "test@qq.com", "sxdw": "實習單位", "sxdw_add": "單位地址", "jjlxrtel": "1234567890" } } ] }
昨天遇到這樣一個問題,在取exttend裏面的信息時,我使用了 以下的方式:php
{
field: 'sxdw'
,
title:
'實習單位'
,
width: 60,
formatter:
function
(value, rec) {
return
rec.extend.sxdw;
}
},
這樣能夠取出sxdw的值,可是帳號類型,性別也顯示實習單位地址的值。不知道問題出在哪,在網上搜索,看到給出的解決辦法都是返回 rec.extend.sxdw;這樣,可是隻返回一個字段,這樣確定能夠返回正確的值了,可是我要返回的是不少個字段。真是沒辦法了,就隨便試 試吧,我把field:’sxdw’改爲field:’extend.sxdw,再運行一次,居然獲得了我想要的結果。java
下面是完整的代碼:json
1 $('#student_list').datagrid({ 2 fit:true, 3 fitColumns : true, 4 rownumbers : true, 5 border : false, 6 striped : true, 7 url:Thinkphp['MODULE']+'/student/getInfo/', 8 toolbar : '#student_tool', 9 rownumbers:true,//顯示行號 10 pagination:true,//顯示分頁工具條 11 pageList : [15, 30, 45], 12 pageNumber : 1, 13 pageSize : 15, 14 sortName : 'id', 15 sortOrder : 'ASC', 16 columns:[[ 17 { 18 field:'id', 19 title:'編號', 20 checkbox:true, 21 width:100, 22 },{ 23 field:'name', 24 title:'姓名', 25 sortable:true, 26 width:100, 27 },{ 28 field:'xiuhao', 29 title:'學號', 30 sortable:true, 31 width:100, 32 },{ 33 field:'exttend.teacher', 34 title:'指導教師', 35 sortable:true, 36 width:100, 37 }, 38 { 39 field:'exttend.tel', 40 title:'電話', 41 sortable:true, 42 width:100, 43 formatter: function (value, rec) { 44 return rec.exttend['tel']; 45 } 46 },{ 47 field:'exttend.qq', 48 title:'QQ', 49 width:80, 50 formatter: function (value, rec) { 51 return rec.exttend['qq']; 52 } 53 },{ 54 field:'exttend.email', 55 title:'電子郵件', 56 width:100, 57 formatter: function (value, row) { 58 return row.exttend.email; 59 } 60 },{ 61 field:'exttend.sxdw', 62 title:'實習單位', 63 width:150, 64 formatter: function (value, row) { 65 return row.exttend.sxdw; 66 } 67 }, { 68 field:'exttend.sxdw_add', 69 title:'實習單位地址', 70 width:150, 71 formatter: function (value, row) { 72 return row.exttend.sxdw_add; 73 } 74 },{ 75 field:'exttend.jjlxrtel', 76 title:'緊急聯繫人電話', 77 width:100, 78 formatter: function (value, row) { 79 return row.exttend.jjlxrtel; 80 } 81 }, 82 ]] 83 });