问题描述
我正在尝试使用 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 (将#修改为@)