about ajax documentation issue

alnux
Member | 139
+
0
-

hi there i have a particular error and i dont know why??
i copy paste the ajax dynamic example

class HomepagePresenter extends \Nette\Application\UI\Presenter
{
    /**
     * This method returns data for the list.
     * Usually this would just request the data from a model.
     * For the purpose of this example, the data is hard-coded.
     * @return array
     */
    private function getTheWholeList()
    {
        return [
            'First',
            'Second',
            'Third'
        ];
    }

    public function renderDefault()
    {
        if (!isset($this->template->list)) {
            $this->template->list = $this->getTheWholeList();
        }
    }

    public function handleUpdate($id)
    {
        $this->template->list = $this->isAjax()
                ? []
                : $this->getTheWholeList();
        $this->template->list[$id] = 'Updated item';
        $this->redrawControl('itemsContainer');
    }
}
<ul n:snippet="itemsContainer">
    {foreach $list as $id => $item}
    <li n:snippet="item-$id">{$item} <a class="ajax" n:href="update! $id">update</a></li>
    {/foreach}
</ul>

but when i try to render on browser show me an route error

Invalid link: No route for Front:Users:Empresa:VentasEmpresa:newedit(id=0, do=change)

the thing is if i take off the $i variable from template, it works but of course without a variable to update specific line

<li n:snippet="item-$id">{$item} <a class="ajax" n:href="update!">update</a></li>

why??
thanks for the help

CZechBoY
Member | 3608
+
-1
-

Error is not in code you send.

alnux
Member | 139
+
0
-

i found a issue about that, i dont why but when if use the same variable in another method appears an error like above, to fix it just change the name of variable and thas all.

Buuuuuut , i have a new issue with nette.ajax.js that when i try to use it with a snnippet does not work (nothing happing into template), the DOM just return me the next

{state: []}
state
:
[]

someone knows how to fix it ??? by the way im using Tomáš Votruba example

Last edited by alnux (2017-05-24 21:49)

CZechBoY
Member | 3608
+
0
-

please send source of that template(s). how can we guess where is problem without any code?