簡體   English   中英

僅在有5個結果時顯示YUI自動填充頁腳

[英]Only show YUI autocomplete footer when there are 5 results

我希望自動完成功能顯示一個頁腳,該頁腳Displaying top 5 results僅當實際顯示Displaying top 5 results時才Displaying top 5 results

到目前為止,我已經設置好了它,以便一開始如果少於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(""));
      };

我沒有嘗試在formatResult函數中進行設置,而是嘗試使用doBeforeExpandContainer函數,它的工作原理就像一個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是將在列表中顯示多少個項目(也與您期望的一樣)。

因此,檢索結果時,每次都會添加頁腳。 然后,在框顯示之前,如果結果不超過五個,則刪除頁腳。

您是否希望僅在有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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM