drlnwji79147769 2014-08-13 07:44
浏览 99
已采纳

如何定义何时应隐藏“显示更多”按钮?

I have a mysql table of products.

I have a product listing page where User has a button "Show more" to load more products on the page. After clicking on this button jQuery calculates how many displayed products are on the page (N) and makes an AJAX request to the table for getting 20 more products (N+20).

Now I should create a trigger when I should hide the button. Which trigger I should choose? What is the best way to define that there are no products.

Please, help.

  • 写回答

5条回答 默认 最新

  • dongzhang5006 2014-08-13 07:57
    关注

    I have no idea how have you reached that functionality since you are not sharing the code and thus I cannot give you the most accurate help, only this one:

    • when loading the page and retrieving the first X rows from DB, retrieve the amount of all rows (matching the search criteria) as well
    • make this count visible to the template
    • in jQuery, count how many rows have you already loaded
      • this means, that on page start you are displaying X rows, the amount of total rows is Y, and the number of currently displayed rows is Z
      • immediately after the page is loaded you need to compare if Z <= Y then do not display button else display the button
      • if the button was displayed I guess you are listening to click event on this button and then performing your AJAX request, here after the AJAX is successfully completed, you need to do Z += X and again compare if Z > Y then hide the button

    That should be your logic, now turn it into your code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 chaquopy python 安卓
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题