primefaces keyup or other ajax event delay

后端 未结 4 1736
一个人的身影
一个人的身影 2020-12-03 04:59

I have something like:


    
         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 05:35

    A quick hack would be adding a delay in onstart of the p:ajax. Define the following function somewhere in your javascript:

    function keyupDelay(request, cfg, delay) {
        delay = delay || 2000;// if no delay supplied, two seconds are the default seconds between ajax requests
        setTimeout(function() {
            cfg.onstart = null;
            request.send(cfg)
        }, delay);
        return false;
    }
    

    Basically that function triggers the ajax request in a certain timeout while returning false for the immediate one, and emptying the onstart on that timedout request in order not to stuck in a nasty loop.

    Then on the p:ajax:

    
    

    The delay parameter is optional here, by default it's 2 seconds.

提交回复
热议问题