我遇到了解決此問題的問題。所以我有一個搜索功能,刷新數據按鈕和一個對話框中的數據網格。第一次加載時,數據通過.xhrGet和json數據正確顯示。當我使用搜索或刷新按鈕時,儘管有正確的數據存儲,我仍然收到錯誤消息。這是我的代碼Dojo datagrid不更新對話框中的數據
dataGrid = dijit.byId("importPayeeGrid");
//dojo.destroy(dataGrid);
// Using dojo.xhrGet, as very little information is being sent
dojo.xhrGet({
url: -----,
handleAs: "json",
// The success callback with result from server
load: function(data) {
var store = new dojo.data.ItemFileReadStore({ data: data });
dataGrid.setStore(store); //the problem here
dataGrid.startup();
dijit.byId('MyDialog').hide();
},
我目前使用的Dojo 1.6和使用DataGrid對話框的內容
是JavaScript內作出的,而不是將其鏈接到一個單獨的頁面
編輯:我可以已發佈完整的代碼,但好...它的1k行JavaScript代碼。所以首先我創建了一個對話框按鈕被點擊
var dialog = dijit.byId("myDialog");
if (dialog == null) {
dialog = new dijit.Dialog({
id: "myDialog",
title: "Processing your request please wait ...",
bgColor: "gray",
bgOpacity: "0.5",
toggle: "fade",
toggleDuration: "250",
dragable: false
});
}
dialog.attr("title", "Payee Catalogue");
dialog.attr("content", "<div style=\"width: 800px; height: 100%;\">" +
"<table style=\"width: 100%;\"> <tr><td>"+
"<div>"+
"<div dojoType=\"dijit.form.DropDownButton\">"+
"<span>Filter Results</span>"+
"<div dojoType=\"dijit.TooltipDialog\"> "+
"<table class=\"myTable center\"> "+
"<tr> "+
" <td>Search:</td>"+
" <td><input type=\"text\" id=\"search_for\""+
" dojoType=\"dijit.form.TextBox\" value=\"\" id=\"search_for\" /></td>"+
"</tr>"+
"<tr>"+
" <td>In:</td>"+
" <td><select id=\"search_in\" dojoType=\"dijit.form.ComboBox\""+
" name=\"search_in\">"+
" <option>Pay to the Order Of</option>"+
" <option>Operating As</option>"+
" <option>Address</option>"+
" <option>Province</option>"+
" </select>"+
" </td>"+
"</tr>"+
"<tr>"+
" <td colspan=\"2\" align=\"right\">"+
" <button dojoType=\"dijit.form.Button\" type=\"button\""+
" onClick=\"queryImportButtons()\">Search</button>"+
" </td>"+
"</tr>"+
"</table>"+
"</div>"+
"</div>"+
"<div dojoType=\"dijit.form.Button\" id=\"refresh\" value=\"ref\""+
" onclick=\"refreshImport()\" title=\"Refresh\">"+
" <img src=\"../images/icons/database_refresh.png\" /> Refresh"+
"</div>"+
" <div dojoType=\"dijit.form.Button\" id=\"LikeF\" class=\"redButton\""+
" iconClass=\"customIcon close\""+
" style=\"disaplay: none; visibility: hidden; float: right;\">LIKE</div>"+
"</div>"+
"</td>"+
"</tr>"+
"</table>"+
"<div id=\"importPayeeGridContainer\" style=\"overflow: scroll;\" ></div><br/>" +
"<div style=\"float: right;\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('myDialog').hide();\">Cancel</div>" +
"<div style=\"float: right;\" dojoType=\"dijit.form.Button\" onclick=\"resizeGrid('importPayeeGrid', this);\">Resize</div>" +
"<div style=\"clear:both;\"> </div></div>");
importPayeeGrid(data);
,然後刷新頁面是在此代碼
function queryData(query) {
var dialog = dijit.byId("MyDialog");
if (dialog == null) {
dialog = new dijit.Dialog({
id: "MyDialog",
title: "Retrieving results please wait ...",
bgColor: "gray",
bgOpacity: "0.5",
toggle: "fade",
toggleDuration: "250",
dragable: false
});
}
dialog.attr("title", "Retrieving results please wait...");
dialog.attr("content", "<img style=\"display: block; margin-left: auto; margin-right: auto;\" src=\"../images/ajax-loader.gif\"/>");
dialog._onKey = function(){ alert("Query can not be canceled."); /*
* do
* nothing
*/ };
dialog.show();
// store the query to be used in the refresh() function
refreshQuery = query;
dataGrid = dijit.byId("importPayeeGrid");
// Using dojo.xhrGet, as very little information is being sent
dojo.xhrGet({
// TODO: this is where the problem occurs
// The URL of the request
url: "payee_profile_import_get.php" + TOKEN_STRING + query,
handleAs: "json",
// The success callback with result from server
load: function(data) {
// set grid data
var store = new SimpleSaveWriteStore({ data: data });
dataGrid.store.close();
dataGrid.setStore(store);
//dataGrid.startup();
dialog.hide();
},
// The error handler
error: function() {
dialog.attr("title", "Display Results");
// set grid error
dialog.attr("content",
"Failed to retrieve results." +
"<div style=\"float: right;\" dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('MyDialog').hide();\">OK</div>");
}
});
}
我已經試過
- 設置時dataGrid存儲在更新前關閉第一個
- commenti納克出dataGrid.startup()
- 使用dataGrid.refresh()
但我得到的是一個消息 「對不起,發生錯誤」。我使用xhrGet而不是直接的原因是因爲我想在數據讀取失敗時顯示錯誤消息,這在我的第一篇文章中沒有涉及。
我決定再次解決這個問題,因爲我的僱主需要這個功能,所以我編輯我的問題,因爲它的長 – 2013-05-01 17:02:24