希望php页面迭代器在外部迭代器中具有过滤器项,而内部迭代器任务将持续交付数据
我正在尝试使用Owl Carousel previous next按钮实现分页,其中paginator应该有一个内部迭代器,负责传递带有偏移量和限制的数据。Outiterator负责向客户端(浏览器)传递数据,这里我想实现一个过滤器,它将决定数据是否可呈现。如果不可呈现,则InnerIterator将获取下一组数据。实际上,如果我需要实现多个过滤器,我也不知道将来应该在哪里实现过滤器。请开导我。这是我当前的实现希望php页面迭代器在外部迭代器中具有过滤器项,而内部迭代器任务将持续交付数据,php,iterator,paginator,filter-iterator,Php,Iterator,Paginator,Filter Iterator,我正在尝试使用Owl Carousel previous next按钮实现分页,其中paginator应该有一个内部迭代器,负责传递带有偏移量和限制的数据。Outiterator负责向客户端(浏览器)传递数据,这里我想实现一个过滤器,它将决定数据是否可呈现。如果不可呈现,则InnerIterator将获取下一组数据。实际上,如果我需要实现多个过滤器,我也不知道将来应该在哪里实现过滤器。请开导我。这是我当前的实现 class SurveyQuestionIterator implements I
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)))