nette ajax, pri scrollu se nacitaji duplicitni videa
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- Mira8
- Člen | 36
Ahoj, snazim se vyresit nacitani novych videi pri scrollovani ajaxem.
V sablonce mam:
{block content}
<div id="photo-gallery" class="gallery">
{snippet reloadAllVideos}
<div n:snippet="listVideos" data-ajax-append="true">
{foreach $videos as $v}
<div class="gallery-photo-container">
<a class="gallery-photo ajax" title="{$v->title}" n:href="show! $v->id" data-gallery>
<img src="{= $v->cdn_img_url_before.$v->img_url}" alt="Play video">
</a>
</div>
{/foreach}
</div>
{/snippet}
</div>
{/block}
Defaultni akce:
class HomepagePresenter extends BasePresenter
{
public function actionDefault()
{
if (!isset($this->template->videos)){
$this->template->videos = $this->videos->getVideos(32, $this->getDegugMode(), false);
}
}
}
Handle akce:
public function handleAddVideos()
{
$httpRequest = $this->getHttpRequest();
if ($httpRequest->isMethod('POST') && $this->isAjax()) {
$category = (array_key_exists('category', $this->params)) ? $this->params['category'] : 'All';
$dateFrom = end($this->template->videos)->published;
$debug = $this->getDegugMode();
$newVideos = $this->videos->search($dateFrom, $category, 32, $debug);
$this->template->videos = $newVideos;
$this->redrawControl('listVideos');
}
}
Vse vicemene funguje, pri 1. scrollu se nactou nova videa, ale po kazdem dalsim se nacitaji jedna a ta sama :/
Problem nejspise bude v $this->template->videos, kde na zacatku se snazim ziskat datum publikovani posledniho videa, tu promenou plnim pred prekleslenim novymi videi, mam tedy za to, ze pri dalsim handle requestu budu mit $this->template->videos naplneno novymi videi, nebo se pletu?
Diky moc za objasneni!