0

我希望自动完成显示一个页脚,该页脚Displaying top 5 results仅在实际显示 5 个结果时显示。

到目前为止,我已将其设置为如果一开始的结果少于 5 个,它不会显示,但是一旦加载了 5 个结果,页脚总是会显示,无论实际显示了多少结果。

请原谅愚蠢的flip噱头。

oAC.formatResult = function(oResultData, sQuery, sResultMatch) {
         var sKey = sResultMatch

         // Extract the part of the match that the user did not type
         var sKeyRemainder = sKey.substr(sQuery.length);


         oAC.setFooter("");
         var aMarkup = ["<div class='myCustomResult'>",
                             "<span style='font-weight:bold'>",
                             sQuery,
                             "</span>",
                             sKeyRemainder,
                             "<br>",
                             "</div>"];

         if (oResultData[2] >= 4) {
            flip = true;
         }
         if (flip) {
            oAC.setFooter("<div style=\"margin-left:5px;\"><span style=\"font-weight:bold;\">See more results for " + sQuery + "</span><br>Showing top 5 results</div>");
         }
         return (aMarkup.join(""));
      };
4

2 回答 2

1

我没有尝试在函数中设置它formatResult,而是尝试使用该doBeforeExpandContainer函数,它就像一个魅力。

oAC.formatResult = function(oResultData, sQuery, sResultMatch) {
   var sKey = sResultMatch

   // Extract the part of the match that the user did not type
   var sKeyRemainder = sKey.substr(sQuery.length);


   oAC.setFooter("");
   var aMarkup = ["<div class='myCustomResult'>",
                       "<span style='font-weight:bold'>",
                       sQuery,
                       "</span>",
                       sKeyRemainder,
                       "<br>",
                       "</div>"];

   oAC.setFooter("<div class=\"ac-footer\"><div class=\"ac-footer-content\"><a class=\"ac-footer-link\" href=\"#\" onclick=\"spandex(this,event,'filter-company');return false;\">See more results for <b>" + sQuery + "</b></a><br><span class=\"ac-footer-sub\">Showing top 5 results</span></div></div>");

   return (aMarkup.join(""));
};

oAC.doBeforeExpandContainer = function(sQuery, oResponse) {
   if (oAC._nDisplayedItems <= 5) {
      oAC.setFooter("");
   }

   return true;
}

doBeforeExpandContainer每次容器打开时都会调用(正如您所期望的那样),并且_nDisplayedItems是列表中将显示的项目数(也如您所期望的那样)。

因此,当检索结果时,每次都会添加页脚。然后,在框显示之前,如果有五个或更少的结果,则删除页脚。

于 2011-02-25T17:00:38.817 回答
0

您希望页脚仅在有 5 个结果时出现?

那你不应该改变吗

if (oResultData[2] >= 4) {
    flip = true;
}

if (oResultData[2] == 4) {  // is this a zero based number? or should this be 5?
    flip = true;
}
else { flip = false } // assuming you don't already reset this in scope

?

于 2011-02-24T16:36:15.367 回答