我正在使用YUI 2.7.0,并且我已经关闭了客户端分页,现在我正在尝试降低服务器端分页(查询可能会返回数千个结果)。现在,没有显示任何结果(我得到“没有找到记录。”消息)。似乎无法在网上找到答案。对alert()的调用显示正确的数字,因此我知道从服务器返回了一些内容。我怀疑问题是在jobsCallback或handleDataReturnPayload中,但是我从那里停留。任何提示?
function jobStatusFormatter(elCell, oRecord, oColumn, oData)
{
var messages =
[
<c:forEach var="x" begin="0" end="17">
"<fmt:message key="job.status.${x}"/>",
</c:forEach>
];
elCell.innerHTML = messages[oData];
}
var jobColumns =
[
{key:"lotNumber", label:"<fmt:message key="job.lotNumber"/>", sortable:true},
{key:"scheduledStartDate", label:"<fmt:message key="job.startDate"/>", sortable:true, formatter:"date"},
{key:"scheduledCompletionDate", label:"<fmt:message key="job.completionDate"/>", sortable:true, formatter:"date"},
{key:"itemNumber", label:"<fmt:message key="job.itemNumber"/>", sortable:true},
{key:"statusType", label:"<fmt:message key="job.statusType"/>", sortable:true, formatter:jobStatusFormatter},
{key:"plannerCode", label:"<fmt:message key="job.plannerCode"/>", sortable:true},
{key:"scheduledGroup", label:"<fmt:message key="job.scheduledGroup"/>", sortable:true},
{key:"organization", label:"<fmt:message key="job.organization"/>", sortable:true}
];
var jobsDataSource = new YAHOO.util.DataSource("<%=request.getContextPath()%>/secure/xml/jobs.do?");
jobsDataSource.connMethodPost = true;
jobsDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
jobsDataSource.responseSchema =
{
resultNode: "job",
fields:
[
"id",
"lotNumber",
"plannerCode",
"scheduledGroup",
"scheduledStartDate",
"scheduledCompletionDate",
"itemNumber",
"statusType",
"organization"
],
metaNode: "jobs",
metaFields:
{
totalResultsAvailable : "totalResultsAvailable",
totalResultsReturned : "totalResultsReturned"
}
};
var jobsConfigs =
{
initialLoad: false,
dynamicData: true,
paginator: new YAHOO.widget.Paginator(
{
rowsPerPage:15,
rowsPerPageOptions : [15,25,50,100]
})
};
var jobsTable = new YAHOO.widget.DataTable("jobsDiv", jobColumns, jobsDataSource, jobsConfigs);
jobsTable.subscribe("rowMouseoverEvent", jobsTable.onEventHighlightRow);
jobsTable.subscribe("rowMouseoutEvent", jobsTable.onEventUnhighlightRow);
jobsTable.set("selectionMode","single");
jobsTable.subscribe("rowClickEvent", function(args)
{
var target = args.target;
var record = this.getRecord(target);
window.location="job.do?id="+record.getData("id");
});
jobsTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload)
{
alert("totalResultsAvailable="+oResponse.meta.totalResultsAvailable+", totalResultsReturned="+oResponse.meta.totalResultsReturned);
oPayload.totalRecords = oResponse.meta.totalResultsAvailable;
return oPayload;
};
var jobsCallback =
{
success : jobsTable.onDataReturnInitializeTable ,
failure : jobsTable.onDataReturnInitializeTable ,
scope : jobsTable
};
function getQueryParams()
{
var form = document.forms[0];
var lotNumber = form.lotNumber.value;
var itemNumber = form.itemNumber.value;
var plannerCode = form.plannerCode.value;
var scheduledGroup = form.scheduledGroup.value;
var statusType = form.statusType.value;
var organization = form.organization.value;
return "lotNumber="+lotNumber+
"&itemNumber="+itemNumber+
"&statusType="+statusType+
"&plannerCode="+plannerCode+
"&scheduledGroup="+scheduledGroup+
"&organization="+organization;
}
/* Called when submit button pressed */
function findJobs()
{
// Sends a request to the DataSource for more data
jobsTable.showTableMessage(YAHOO.widget.DataTable.MSG_LOADING);
jobsDataSource.sendRequest(getQueryParams(), jobsCallback);
}
答案 0 :(得分:3)
你可能在警报后立即收到错误,但它被吞没了。 FireBug Break on All Errors配置可以确认这一点。机会是oPayload未定义。它由回调对象中的参数属性值设置。
所以你应该能够用
解决这个问题jobsCallback = {
success : jobsTable.onDataReturnInitializeTable,
failure : jobsTable.onDataReturnInitializeTable,
scope : jobsTable,
argument : {}
};
或
jobsTable.handleDataReturnPayload = function(oRequest, oResponse, oPayload) {
oPayload = oPayload || {};
oPayload.totalRecords = oResponse.meta.totalResultsAvailable;
return oPayload;
};
HTH