Předání proměnné z ajaxu do šablony

jirisolc
Člen | 17
+
0
-

Ahoj,
po kliknutí na checkbox zavolám AJAXový požadavek, na jehož základě vyberu data z databáze a překreslím snippet.
Daří se mi vše až na překreslení snippetu či předání nových dat do šablony (opravdu nevím, kde dělám chybu).

AJAX mi vrací správná data.

class HomepagePresenter extends BasePresenter {

    protected $shopManager;
    protected $filters;
    protected $shopList = null;

    public function __construct(Model\ShopManager $shopManager, Nette\Http\Session $session) {
        parent::__construct();
        $this->shopManager = $shopManager;
        $this->filters = $session->getSection('filters');
    }

    public function renderDefault($page = 1) {
        $shopCount = $this->shopManager->getShopCount();

        $paginator = new \Nette\Utils\Paginator();
        $paginator->setItemCount($shopCount);
        $paginator->setItemsPerPage(12);
        $paginator->setPage($page);


        if ($this->shopList != null) {
            $this->template->shopList = $this->shopList;
            \Tracy\Debugger::barDump($this->template->shopList);
        } else {
            $this->shopList = $this->shopManager->getShopsWithLimit($paginator->getLength(), $paginator->getOffset());
            $this->template->shopList = $this->shopList;
        }
        $this->template->categories = $this->shopManager->getCategories();
        $this->template->paginator = $paginator;
    }

    public function handleFilter($id) {
        $activeFilters = $this->filters->filterValues;
        if (!in_array($id, $activeFilters)) {
            array_push($activeFilters, $id);
        } else {
            if (($key = array_search($id, $activeFilters)) !== false) {
                unset($activeFilters[$key]);
            }
        }
        $this->shopList = $this->shopManager->getShopsWithLimit(10, 12, $activeFilters);
        if ($this->isAjax()) {
            $this->filters->filterValues = $activeFilters;
            //\Tracy\Debugger::barDump($this->isControlInvalid('shopItems'));
            //\Tracy\Debugger::barDump($this->template->shopList);

            $this->redrawControl('shopItems');
        }
    }

    protected function createComponentFilterForm() {
        $form = new Form();
        $form->addCheckBoxList('categories', 'Filtr', $this->createArray($this->shopManager->getCategories()))
                ->getSeparatorPrototype()->setName(NULL);
        return $form;
    }
<section class="sales">
    <div class="container sales-container">
        {snippet shopItems}
            <div class="row sales-row">
                {dump $shopList}
                {foreach $shopList as $item}
                    <a href='#' class="col-xs-12 col-sm-6 col-md-4 col-lg-3 text-center shop-item-container">
                        <div class="shop-item">
                            <img src="{$basePath}{$item->logo}" alt="{$item->name}">
                            <p>{$item->name}</p>
                            <p>- Sport, Oblečení, Ostatní</p>
                        </div>
                    </a>
                {/foreach}
            </div>
            <div class="pagination">
                {if !$paginator->isFirst()}
                    <a n:href="default, 1">První</a>
                    &nbsp;|&nbsp;
                    <a n:href="default, $paginator->page-1">Předchozí</a>
                    &nbsp;|&nbsp;
                {/if}

                Stránka {$paginator->page} z {$paginator->pageCount}

                {if !$paginator->isLast()}
                    &nbsp;|&nbsp;
                    <a n:href="default, $paginator->page+1">Další</a>
                    &nbsp;|&nbsp;
                    <a n:href="default, $paginator->pageCount">Poslední</a>
                {/if}
            </div>
        {/snippet}
    </div>
</section>

<script>
	$('.filter-checkbox').click(function () {
    	var id = $(this).val();
        $.get({link filter!}, { id:id });
    });
</script>

Editoval jirisolc (22. 11. 2017 19:04)