0

我正在尝试使用 Owl Carousel 上一个下一个按钮实现分页,其中分页器应该有一个内部迭代器,负责传递具有偏移和限制的数据。outerIterator 负责将数据传递给客户端(浏览器),在这里我想实现一个过滤器来决定数据是否可呈现。如果无法呈现,则 InnerIterator 将获取下一组数据。实际上,如果我需要实现多个过滤器,我也不知道将来应该在哪里实现过滤器。请赐教。这是我目前的实现。

 class SurveyQuestionIterator implements InnerIterator {     public
 function rewind()    {
           $this->postion=0;
           $this->current_page= $this->client->getPage($offset, $limit);    }
        public function next()    {
          ++$this->position;
           if(!empty($this->current_page)) $this->getPage($next_offset, $limit);
 
    }    public function current()    {
      new ArrayIterator($this->current_page);    }
 
 }
 
 class MyOuterIterator Implements Iterator {
      public function __construct(Iterator $iterator)
      {
        $this->innerIterator= $iterator;
      }
      public function rewind()
     {
         $this->innerIterator->rewind(); // It will deliver continuous data
     }
     private function skipEmptyIterator()
     {
        while(! $this->outerIterator->valid())
          {
            $this->innerIterator->next();
            if($this->innerIterator->valid())
            {
              $this->outerIterator= $this->getIterator();
              $this->outerIterator->rewind();
            }else
            {
                 $this->outerIterator= null;
                 break;
            }
          }
     }
     public function current()
       {
         return $this->outerIterator->current();
       }
 
 }

在带有ajax请求的客户端我会打电话

foreach(new MyOuterIterator(new SurveyQuestionIterator($client,
 $offset)))
4

0 回答 0