0

我有一个显示搜索信息的 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();

        }
4

1 回答 1

0

使用关键字 var 在函数外部定义 searchResultsStore 和 searchResultsDataGrid 变量,并在没有关键字的函数中全局使用它们:

var searchResultsDataGrid = null; 
function abc() {
   searchResultsDataGrid = new Abc(...); 
}

如果这没有帮助,您可以使用 dojo.empty() 或 destroyDescendants() 显式清空 ResultDiv。

希望我能帮上忙。

于 2012-08-13T14:19:57.123 回答