easyui datagrid如何加载通过ajax获得的数据??
从ajax中获得了数据,然后怎么把多个json对象让datagrid加载???
// 构建设备总览列表
$('#dg_machine_list').datagrid({
title : '设备列表模式',
iconCls : 'icon-a_detail',
fit : true,
fitColumns : true,
rownumbers : true,
pagination : true,
singleSelect : true,
border : false,
striped : true,
toolbar : [ {
text : '查看详情',
iconCls : 'icon-script_link',
handler : function() {
viewDetail();
}
}, '-', {
iconCls : 'icon-help',
handler : function() {
alert('帮助按钮');
}
} ],
columns : [ [ {
field : 'unid',
title : 'UNID',
width : 100,
align : 'center',
hidden : true
}, {
field : 'machine_name',
title : '设备名称',
width : 100,
align : 'center'
}, {
field : 'machine_type',
title : '设备类型',
width : 100,
align : 'center'
}, {
field : 'num_recoder',
title : '备案编号',
width : 100,
align : 'center'
}, {
field : 'work_state',
title : '当前状态',
width : 100,
align : 'center'
}, {
field : 'update_time',
title : '更新时间',
width : 100,
align : 'center'
}, {
field : 'moment',
title : '力矩(KN.m)',
width : 70,
align : 'center'
}, {
field : 'load',
title : '载重(t)',
width : 50,
align : 'center'
}, {
field : 'height',
title : '高度(m)',
width : 50,
align : 'center'
}, {
field : 'range',
title : '幅度(m)',
width : 50,
align : 'center'
}, {
field : 'angle',
title : '角度(度)',
width : 50,
align : 'center'
}, {
field : 'wind_speed',
title : '风速(m/s)',
width : 50,
align : 'center'
}, {
field : 'dip_angle',
title : '倾角(度)',
width : 50,
align : 'center'
}, {
field : 'alarm_info',
title : '报警信息',
width : 100,
align : 'center'
} ] ]
});
// 先通过ajax获取数据,然后再传给datagrid
// https://bas.gimiscloud.com/api/crane/machinelist
// json/data_machine_list.json
$.ajax({
method : 'GET',
url : 'https://bas.gimiscloud.com/api/crane/machinelist',
async : false,
dataType : 'json',
beforeSend : function(jqXHR) {
jqXHR.setRequestHeader('Authorization', 'Bearer '
+ '3feee5b76d8e698f4e5e29c626eb9dc2');
},
success : function(data) {
for ( var machine in data) {
alert(data[machine].name);
var a = [ {
'unid' : data[machine].unid,
'machine_name' : data[machine].name,
'machine_type' : data[machine].type,
'num_recoder' : data[machine].unid,
'work_state' : data[machine].online,
'update_time' : data[machine].date,
'moment' : data[machine].torque,
'load' : data[machine].capa,
'height' : data[machine].hook_height,
'range' : data[machine].radius,
'angle' : data[machine].angle,
'wind_speed' : data[machine].wind_velocity,
'dip_angle' : data[machine].obliquity,
'alarm_info' : data[machine].content
} ];
$('#dg_machine_list').datagrid('loadData', a);
}
},
error : function() {
alert('error');
}
});
------解决思路----------------------
多看下API就好了。。
------解决思路----------------------
在后台拼接json