標籤:des style blog io color ar sp for 資料
今天用easyui 的datagrid綁定資料時,後台提供的資料是實體類類型的,其中有一個實體類A的屬性b是另一個實體類B類型的,而前台需要顯示b的屬性c,這下就悲劇了,前台沒法直接綁定了,後來腦筋一轉,想到了datagrid的列屬性formatter,formatter提供了row,這樣的話我們在formatter裡面指定一下不就可以了嗎
於是~
function dgDevice_datagrid() { $(‘#dgDevice‘).datagrid({ url: ‘DeviceList.ashx?action=GetDevices‘, toolbar: ‘#tb1‘, width: 540, singleSelect: true, remoteSort: true, sortName: ‘SaleDate‘, sortOrder: ‘desc‘, rownumbers: true, columns: [[ { title: ‘裝置ID‘, field: ‘DeviceID‘, width: 190, align: ‘center‘ }, { title: ‘出廠日期‘, field: ‘ExFactoryDate‘, width: 110, align: ‘center‘, formatter: function (val) { return formatDate(val, "yyyy-MM-dd"); } }, { title: ‘售賣日期‘, field: ‘SaleDate‘, width: 110, align: ‘center‘, formatter: function (val) { return formatDate(val, "yyyy-MM-dd"); } }, { title: ‘賬戶‘, field: ‘AccountName‘, width: 80, align: ‘center‘, formatter: function (value, row, index) { return row.Account.AccountName; } } ]], onSelect: function (rowIndex, rowData) { dgSensor_datagrid(rowData.DeviceID); } }); }
完美~
easyui datagrid 綁定json對象屬性的屬性