如何解决希望php分页迭代器在外部迭代器中带有过滤项,而内部迭代器任务将不断传递数据
我正在尝试使用 Owl Carousel 上一个下一个按钮实现分页,其中分页器应该有一个内部迭代器,负责提供具有偏移和限制的数据。外部迭代器负责将数据传递给客户端(浏览器),在这里我想实现一个过滤器来决定数据是否可呈现。如果不呈现,则 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)))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。