在我的 dojo.xhrGet
中,我指定了这个 load:
:
load: function (data) {
// reset data display containers
dojo.addClass("search_results", "hide_on_load");
dojo.byId("search_results_found").innerHTML = "";
// populate table with new results.
dojo.byId("search_results_found").innerHTML = "" + data.length + " search result(s) found.";
// when data is from an XHR request, you must transform it into a store.
// See: http://stackoverflow.com/questions/2423459/datagrid-in-dojo-with-json-data-from-a-servlet
var items = dojo.map(data, function (res_row) {
return {
'Id': res_row.Id,
'Name': res_row.Name,
'VisitType': res_row.VisitType,
'VisitDate': res_row.VisitDate
};
});
var store = new dojo.data.ItemFileReadStore({
data: {
items: items
}
});
var res_layout = [
{field: 'Id', name: 'ID', width: '10%'},
{field: 'Name', name: 'Site Name', width: '50%'},
{field: 'VisitType', name: 'Visit Type', width: '20%'},
{field: 'VisitDate', name: 'Visit Date', width: '20%'}
];
// create a new grid:
var res_grid = new dojox.grid.DataGrid({
store: store,
structure: res_layout,
rowsPerPage: 10
}, document.createElement('div'));
// append the new grid to the div "search_results_table":
dojo.byId("search_results_table").appendChild(res_grid.domNode);
// Call startup, in order to render the grid:
res_grid.startup();
dojo.removeClass("search_results", "hide_on_load");
standby.hide();
},
而且,html 是:
<!-- Search Results Table -->
<div id="search_results" class="hide_on_load">
<div id="search_results_found"></div>
<div id="search_results_table"></div>
</div>
在这个脚本的最后,网格没有显示。
我删除了 hide_on_load css 类选择器,这样我就可以将它排除在外。但是,这没有帮助。
查看控制台,没有记录任何错误。
此外,编写各种对象(res_grid、store 等)都会产生看起来正确的输出。
有人可以提供一些关于如何让它显示的帮助吗?
谢谢!
更新:
当我在这段代码运行后检查 DOM 时,我看到了用标题创建的表格,但是当我去寻找带有搜索结果的实际表格时(在 div class=dojoxGridContent
下) ,它不在那里。
更新 2:
我也指定了样式:
<style type="text/css">
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/Grid.css";
@import "http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojox/grid/resources/claroGrid.css";
.dojoxGrid table { margin: 0; }
</style>
最佳答案
确保通过放置网格的 div 上的样式属性设置大小,并且不要忘记为网格导入 CSS 文件,例如:
<style type="text/css">
@import "dojoroot/dojox/grid/resources/Grid.css";
@import "dojoroot/dojox/grid/resources/soriaGrid.css";
.dojoxGrid table {
margin: 0;
}
</style>
注意:用您正在使用的任何主题替换 soria...
...并且不要忘记为网格的 dom 节点设置大小:
<div id="gridnode" style="width:100%; height:500px;"></div>
关于javascript - Dojo DataGrid 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8387457/