我想在数据网格中显示数据。数据由 URL 检索,使用 $.get 方法作为 JSon 类型。我没有收到任何错误。但也没有得到数据网格。这是我的脚本代码::
<script type="text/javascript">
$("document").ready(function(){
$('#contentpaneid').bind('click', getInfoFromServer);
function getInfoFromServer(){
$.get("http://localhost:8080/2_8_2012/jsp/GetJson.jsp?random=" + new Date().getTime(), function (result) {
success:postToPage(result),
alert('Load was performed.');
},"Json");
function postToPage(data){
alert(data);
var storedata = {
identifier:"ID",
items: data //[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":3,"Names":"Rohit"},{"ID":21,"Names":"Rakesh","Email":"askjhjk"}]
};
var store1 = new dojo.data.ItemFileWriteStore({data: storedata}) ;
var gridStructure =[[
{ field: "ID",
name: "ID_Emp",
width: "20%",
classes:"firstName"
},
{
field: "Names",
name: "Name",
width: "20%",
classes: "firstName"
},
{ field: "Email",
name: "Mail",
width: "20%",
classes:"firstName"
}
]
];
var grid = new dojox.grid.DataGrid({
store: store1,
structure: gridStructure,
rowSelector: '30px',
selectionMode: "single",
autoHeight:true,
columnReordering:true
},'gridDiv');
grid.startup();
dojo.connect(grid, "onSelectionChanged", grid, function(){
var items = grid.selection.getSelected();
// do something with the selected items
dojo.forEach(items, function(item){
var v = grid.store.getValue(item, "Names");
function showDialog() {
dojo.require('dijit.Tooltip');
dijit.byId("terms").show();
}
showDialog();
}, grid);
});
dojo.connect(grid, "onCellClick", grid, function sendmail(){
var items = grid.selection.getSelected();
dojo.forEach(items, function(item){
var v1 = grid.store.getValue(item, "Email");
alert(v1);
request.setAttribute("variablemail", v1);
});
});
};
};
});
</script>
我的标记代码是::
<div id="contentpaneid" dojoType="dijit.layout.ContentPane" title="Pending Activities" style="background-image: url('http://localhost:8080/2_8_2012/images/17.png');">
<div data-dojo-id="gridDiv" title="Simple Grid" style="width:900px; height:200px;">
当我单击内容窗格内部时,我得到警报(数据)输出,就像通过 $.get 方法以 JSon 检索数据时一样::
[Object object][Object object][Object object](The number of [Object object] depends on number of entries in Database)
以文本形式检索数据时输出为::
[{"ID":1,"Names":"Shantanu","Email":"shantanu.tomar@gmail.com"},{"ID":2,"Names":"Mayur","Email":"mayur.sharma@gmail.com"},{"ID":3,"Names":"Rohit"},{"ID":21,"Names":"Rakesh","Email":"askjhjk"},{"ID":22,"Names":"Hello"}]
现在,当我更新数据时,我确实收到了数据警报 ryt。即值在警报(数据)中得到更新,我的 $.get 函数工作正常。并且还收到 alert('Load was executed.') 消息。但是网格没有显示出来。它不是数据。但网格也没有显示。单击时仅显示警告框。而已。我在哪里犯错?我应该将数据作为文本或 JSON 检索,以便将值正确传递给“items:”。请帮忙。我希望在单击事件时,网格会根据数据库的更改自行刷新。谢谢。