当我点击搜索按钮时,我有一个DataGrid显示创建的搜索信息并将其附加到我的结果窗格div。问题是,当我再次点击搜索时,第一个仍然在那里,所以新的网格被附加,并且它不会出现,因为第一个填充了div。有没有办法获得对原始窗格的引用,重置商店并刷新它?由于搜索功能结束且变量超出范围,因此我松开了对该对象的引用。 Dojo是否使用全局变量,如果它确实如何设置这些变量,或者有不同的方法吗?
由于
代码:
function loadAdvancedSearchResultsTable( ) {
console.debug("inside loadAdvancedSearchResultsTable()");
// See: http://dojo-toolkit.33424.n3.nabble.com/Dojo-dijit-form-Form-form-submit-on-keyboard-enter-td3359280.html
var name = dijit.byId('search_name').get("value");
var callingNumber = dijit.byId("search_callingnumber").get("value");
var calledNumber = dijit.byId('search_callednumber').get("value");
var durationBetweenStart = dijit.byId('search_durationbetween_start').get("value");
var durationBetweenEnd = dijit.byId('search_durationbetween_end').get("value");
var dateStart = dijit.byId('search_datebetween_start').get("value");
var dateEnd = dijit.byId('search_datebetween_end').get("value");
//var executeSearchPhpLink = "modules/content_panes/searchresults.php?";
var executeSearchPhpLink = "modules/data_store/search_results_datastore.php?";
var executeSearchPhpLinkHasElement = false;
if(name != "") {
executeSearchPhpLink += "name=" + name;
executeSearchPhpLinkHasElement = true;
}
if(callingNumber != "") {
if(executeSearchPhpLinkHasElement == true) {
executeSearchPhpLink += "&";
}
executeSearchPhpLink += "callingNumber=" + callingNumber;
executeSearchPhpLinkHasElement = true;
}
if(calledNumber != "") {
if(executeSearchPhpLinkHasElement == true) {
executeSearchPhpLink += "&";
}
executeSearchPhpLink += "calledNumber=" + calledNumber;
executeSearchPhpLinkHasElement = true;
}
if(durationBetweenStart != "") {
if(executeSearchPhpLinkHasElement == true) {
executeSearchPhpLink += "&";
}
executeSearchPhpLink += "durationBetweenStart=" + durationBetweenStart;
executeSearchPhpLinkHasElement = true;
}
if(durationBetweenEnd != "") {
if(executeSearchPhpLinkHasElement == true) {
executeSearchPhpLink += "&";
}
executeSearchPhpLink += "durationBetweenEnd=" + durationBetweenEnd;
executeSearchPhpLinkHasElement = true;
}
if(dateStart != null) {
if(executeSearchPhpLinkHasElement == true) {
executeSearchPhpLink += "&";
}
executeSearchPhpLink += "dateStart=" + dateStart;
executeSearchPhpLinkHasElement = true;
}
if(dateEnd != null) {
if(executeSearchPhpLinkHasElement == true) {
executeSearchPhpLink += "&";
}
executeSearchPhpLink += "dateEnd=" + dateEnd;
executeSearchPhpLinkHasElement = true;
}
console.debug("About to set the content pane href to " + executeSearchPhpLink);
// Create the data store to be used
var searchResultsStore = new dojo.data.ItemFileReadStore({url: executeSearchPhpLink});
// Set the layout structure
var gridStructure = [
{ field: 'user', name:'Name', width:'15%' },
{ field: 'dn', name:'Calling Number', width:'15%' },
{ field: 'origcalledparty', name:'Called Number', width:'15%' },
{ field: 'callstarttime', name:'Start Time', width:'10%' },
{ field: 'callendtime', name:'End Time', width:'10%' },
{ field: 'duration', name:'Duration', width:'10%' },
{ field: 'datetime', name:'Date', width:'25%' }
];
// Construct the data grid
var searchResultsDataGrid = new dojox.grid.DataGrid({
store: searchResultsStore,
clientSort: true,
rowSelector: true,
structure: gridStructure
},document.createElement('div'));
// Append the new grid to the search results content pane
dojo.byId("searchResultsContentPane").appendChild(searchResultsDataGrid.domNode);
// Call startup to render the grid
searchResultsDataGrid.startup();
}
答案 0 :(得分:0)
使用关键字var在函数外部定义searchResultsStore和searchResultsDataGrid变量,并在没有关键字的函数中全局使用它们:
var searchResultsDataGrid = null;
function abc() {
searchResultsDataGrid = new Abc(...);
}
如果这没有帮助,您可以使用dojo.empty()或destroyDescendants()显式清空ResultDiv。
希望我能提供帮助。